index.iife.js 239 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793
  1. (function (exports, shared, vue) {
  2. 'use strict';
  3. function computedAsync(evaluationCallback, initialState, optionsOrRef) {
  4. let options;
  5. if (vue.isRef(optionsOrRef)) {
  6. options = {
  7. evaluating: optionsOrRef
  8. };
  9. } else {
  10. options = optionsOrRef || {};
  11. }
  12. const {
  13. lazy = false,
  14. evaluating = void 0,
  15. shallow = true,
  16. onError = shared.noop
  17. } = options;
  18. const started = vue.ref(!lazy);
  19. const current = shallow ? vue.shallowRef(initialState) : vue.ref(initialState);
  20. let counter = 0;
  21. vue.watchEffect(async (onInvalidate) => {
  22. if (!started.value)
  23. return;
  24. counter++;
  25. const counterAtBeginning = counter;
  26. let hasFinished = false;
  27. if (evaluating) {
  28. Promise.resolve().then(() => {
  29. evaluating.value = true;
  30. });
  31. }
  32. try {
  33. const result = await evaluationCallback((cancelCallback) => {
  34. onInvalidate(() => {
  35. if (evaluating)
  36. evaluating.value = false;
  37. if (!hasFinished)
  38. cancelCallback();
  39. });
  40. });
  41. if (counterAtBeginning === counter)
  42. current.value = result;
  43. } catch (e) {
  44. onError(e);
  45. } finally {
  46. if (evaluating && counterAtBeginning === counter)
  47. evaluating.value = false;
  48. hasFinished = true;
  49. }
  50. });
  51. if (lazy) {
  52. return vue.computed(() => {
  53. started.value = true;
  54. return current.value;
  55. });
  56. } else {
  57. return current;
  58. }
  59. }
  60. function computedInject(key, options, defaultSource, treatDefaultAsFactory) {
  61. let source = vue.inject(key);
  62. if (defaultSource)
  63. source = vue.inject(key, defaultSource);
  64. if (treatDefaultAsFactory)
  65. source = vue.inject(key, defaultSource, treatDefaultAsFactory);
  66. if (typeof options === "function") {
  67. return vue.computed((ctx) => options(source, ctx));
  68. } else {
  69. return vue.computed({
  70. get: (ctx) => options.get(source, ctx),
  71. set: options.set
  72. });
  73. }
  74. }
  75. function createReusableTemplate(options = {}) {
  76. const {
  77. inheritAttrs = true
  78. } = options;
  79. const render = vue.shallowRef();
  80. const define = /* #__PURE__ */ vue.defineComponent({
  81. setup(_, { slots }) {
  82. return () => {
  83. render.value = slots.default;
  84. };
  85. }
  86. });
  87. const reuse = /* #__PURE__ */ vue.defineComponent({
  88. inheritAttrs,
  89. setup(_, { attrs, slots }) {
  90. return () => {
  91. var _a;
  92. if (!render.value && process.env.NODE_ENV !== "production")
  93. throw new Error("[VueUse] Failed to find the definition of reusable template");
  94. const vnode = (_a = render.value) == null ? void 0 : _a.call(render, { ...keysToCamelKebabCase(attrs), $slots: slots });
  95. return inheritAttrs && (vnode == null ? void 0 : vnode.length) === 1 ? vnode[0] : vnode;
  96. };
  97. }
  98. });
  99. return shared.makeDestructurable(
  100. { define, reuse },
  101. [define, reuse]
  102. );
  103. }
  104. function keysToCamelKebabCase(obj) {
  105. const newObj = {};
  106. for (const key in obj)
  107. newObj[shared.camelize(key)] = obj[key];
  108. return newObj;
  109. }
  110. function createTemplatePromise(options = {}) {
  111. let index = 0;
  112. const instances = vue.ref([]);
  113. function create(...args) {
  114. const props = vue.shallowReactive({
  115. key: index++,
  116. args,
  117. promise: void 0,
  118. resolve: () => {
  119. },
  120. reject: () => {
  121. },
  122. isResolving: false,
  123. options
  124. });
  125. instances.value.push(props);
  126. props.promise = new Promise((_resolve, _reject) => {
  127. props.resolve = (v) => {
  128. props.isResolving = true;
  129. return _resolve(v);
  130. };
  131. props.reject = _reject;
  132. }).finally(() => {
  133. props.promise = void 0;
  134. const index2 = instances.value.indexOf(props);
  135. if (index2 !== -1)
  136. instances.value.splice(index2, 1);
  137. });
  138. return props.promise;
  139. }
  140. function start(...args) {
  141. if (options.singleton && instances.value.length > 0)
  142. return instances.value[0].promise;
  143. return create(...args);
  144. }
  145. const component = /* #__PURE__ */ vue.defineComponent((_, { slots }) => {
  146. const renderList = () => instances.value.map((props) => {
  147. var _a;
  148. return vue.h(vue.Fragment, { key: props.key }, (_a = slots.default) == null ? void 0 : _a.call(slots, props));
  149. });
  150. if (options.transition)
  151. return () => vue.h(vue.TransitionGroup, options.transition, renderList);
  152. return renderList;
  153. });
  154. component.start = start;
  155. return component;
  156. }
  157. function createUnrefFn(fn) {
  158. return function(...args) {
  159. return fn.apply(this, args.map((i) => shared.toValue(i)));
  160. };
  161. }
  162. const defaultWindow = shared.isClient ? window : void 0;
  163. const defaultDocument = shared.isClient ? window.document : void 0;
  164. const defaultNavigator = shared.isClient ? window.navigator : void 0;
  165. const defaultLocation = shared.isClient ? window.location : void 0;
  166. function unrefElement(elRef) {
  167. var _a;
  168. const plain = shared.toValue(elRef);
  169. return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
  170. }
  171. function useEventListener(...args) {
  172. let target;
  173. let events;
  174. let listeners;
  175. let options;
  176. if (typeof args[0] === "string" || Array.isArray(args[0])) {
  177. [events, listeners, options] = args;
  178. target = defaultWindow;
  179. } else {
  180. [target, events, listeners, options] = args;
  181. }
  182. if (!target)
  183. return shared.noop;
  184. if (!Array.isArray(events))
  185. events = [events];
  186. if (!Array.isArray(listeners))
  187. listeners = [listeners];
  188. const cleanups = [];
  189. const cleanup = () => {
  190. cleanups.forEach((fn) => fn());
  191. cleanups.length = 0;
  192. };
  193. const register = (el, event, listener, options2) => {
  194. el.addEventListener(event, listener, options2);
  195. return () => el.removeEventListener(event, listener, options2);
  196. };
  197. const stopWatch = vue.watch(
  198. () => [unrefElement(target), shared.toValue(options)],
  199. ([el, options2]) => {
  200. cleanup();
  201. if (!el)
  202. return;
  203. const optionsClone = shared.isObject(options2) ? { ...options2 } : options2;
  204. cleanups.push(
  205. ...events.flatMap((event) => {
  206. return listeners.map((listener) => register(el, event, listener, optionsClone));
  207. })
  208. );
  209. },
  210. { immediate: true, flush: "post" }
  211. );
  212. const stop = () => {
  213. stopWatch();
  214. cleanup();
  215. };
  216. shared.tryOnScopeDispose(stop);
  217. return stop;
  218. }
  219. let _iOSWorkaround = false;
  220. function onClickOutside(target, handler, options = {}) {
  221. const { window = defaultWindow, ignore = [], capture = true, detectIframe = false } = options;
  222. if (!window)
  223. return shared.noop;
  224. if (shared.isIOS && !_iOSWorkaround) {
  225. _iOSWorkaround = true;
  226. Array.from(window.document.body.children).forEach((el) => el.addEventListener("click", shared.noop));
  227. window.document.documentElement.addEventListener("click", shared.noop);
  228. }
  229. let shouldListen = true;
  230. const shouldIgnore = (event) => {
  231. return shared.toValue(ignore).some((target2) => {
  232. if (typeof target2 === "string") {
  233. return Array.from(window.document.querySelectorAll(target2)).some((el) => el === event.target || event.composedPath().includes(el));
  234. } else {
  235. const el = unrefElement(target2);
  236. return el && (event.target === el || event.composedPath().includes(el));
  237. }
  238. });
  239. };
  240. function hasMultipleRoots(target2) {
  241. const vm = shared.toValue(target2);
  242. return vm && vm.$.subTree.shapeFlag === 16;
  243. }
  244. function checkMultipleRoots(target2, event) {
  245. const vm = shared.toValue(target2);
  246. const children = vm.$.subTree && vm.$.subTree.children;
  247. if (children == null || !Array.isArray(children))
  248. return false;
  249. return children.some((child) => child.el === event.target || event.composedPath().includes(child.el));
  250. }
  251. const listener = (event) => {
  252. const el = unrefElement(target);
  253. if (event.target == null)
  254. return;
  255. if (!(el instanceof Element) && hasMultipleRoots(target) && checkMultipleRoots(target, event))
  256. return;
  257. if (!el || el === event.target || event.composedPath().includes(el))
  258. return;
  259. if (event.detail === 0)
  260. shouldListen = !shouldIgnore(event);
  261. if (!shouldListen) {
  262. shouldListen = true;
  263. return;
  264. }
  265. handler(event);
  266. };
  267. let isProcessingClick = false;
  268. const cleanup = [
  269. useEventListener(window, "click", (event) => {
  270. if (!isProcessingClick) {
  271. isProcessingClick = true;
  272. setTimeout(() => {
  273. isProcessingClick = false;
  274. }, 0);
  275. listener(event);
  276. }
  277. }, { passive: true, capture }),
  278. useEventListener(window, "pointerdown", (e) => {
  279. const el = unrefElement(target);
  280. shouldListen = !shouldIgnore(e) && !!(el && !e.composedPath().includes(el));
  281. }, { passive: true }),
  282. detectIframe && useEventListener(window, "blur", (event) => {
  283. setTimeout(() => {
  284. var _a;
  285. const el = unrefElement(target);
  286. if (((_a = window.document.activeElement) == null ? void 0 : _a.tagName) === "IFRAME" && !(el == null ? void 0 : el.contains(window.document.activeElement))) {
  287. handler(event);
  288. }
  289. }, 0);
  290. })
  291. ].filter(Boolean);
  292. const stop = () => cleanup.forEach((fn) => fn());
  293. return stop;
  294. }
  295. function createKeyPredicate(keyFilter) {
  296. if (typeof keyFilter === "function")
  297. return keyFilter;
  298. else if (typeof keyFilter === "string")
  299. return (event) => event.key === keyFilter;
  300. else if (Array.isArray(keyFilter))
  301. return (event) => keyFilter.includes(event.key);
  302. return () => true;
  303. }
  304. function onKeyStroke(...args) {
  305. let key;
  306. let handler;
  307. let options = {};
  308. if (args.length === 3) {
  309. key = args[0];
  310. handler = args[1];
  311. options = args[2];
  312. } else if (args.length === 2) {
  313. if (typeof args[1] === "object") {
  314. key = true;
  315. handler = args[0];
  316. options = args[1];
  317. } else {
  318. key = args[0];
  319. handler = args[1];
  320. }
  321. } else {
  322. key = true;
  323. handler = args[0];
  324. }
  325. const {
  326. target = defaultWindow,
  327. eventName = "keydown",
  328. passive = false,
  329. dedupe = false
  330. } = options;
  331. const predicate = createKeyPredicate(key);
  332. const listener = (e) => {
  333. if (e.repeat && shared.toValue(dedupe))
  334. return;
  335. if (predicate(e))
  336. handler(e);
  337. };
  338. return useEventListener(target, eventName, listener, passive);
  339. }
  340. function onKeyDown(key, handler, options = {}) {
  341. return onKeyStroke(key, handler, { ...options, eventName: "keydown" });
  342. }
  343. function onKeyPressed(key, handler, options = {}) {
  344. return onKeyStroke(key, handler, { ...options, eventName: "keypress" });
  345. }
  346. function onKeyUp(key, handler, options = {}) {
  347. return onKeyStroke(key, handler, { ...options, eventName: "keyup" });
  348. }
  349. const DEFAULT_DELAY = 500;
  350. const DEFAULT_THRESHOLD = 10;
  351. function onLongPress(target, handler, options) {
  352. var _a, _b;
  353. const elementRef = vue.computed(() => unrefElement(target));
  354. let timeout;
  355. let posStart;
  356. let startTimestamp;
  357. let hasLongPressed = false;
  358. function clear() {
  359. if (timeout) {
  360. clearTimeout(timeout);
  361. timeout = void 0;
  362. }
  363. posStart = void 0;
  364. startTimestamp = void 0;
  365. hasLongPressed = false;
  366. }
  367. function onRelease(ev) {
  368. var _a2, _b2, _c;
  369. const [_startTimestamp, _posStart, _hasLongPressed] = [startTimestamp, posStart, hasLongPressed];
  370. clear();
  371. if (!(options == null ? void 0 : options.onMouseUp) || !_posStart || !_startTimestamp)
  372. return;
  373. if (((_a2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _a2.self) && ev.target !== elementRef.value)
  374. return;
  375. if ((_b2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _b2.prevent)
  376. ev.preventDefault();
  377. if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
  378. ev.stopPropagation();
  379. const dx = ev.x - _posStart.x;
  380. const dy = ev.y - _posStart.y;
  381. const distance = Math.sqrt(dx * dx + dy * dy);
  382. options.onMouseUp(ev.timeStamp - _startTimestamp, distance, _hasLongPressed);
  383. }
  384. function onDown(ev) {
  385. var _a2, _b2, _c, _d;
  386. if (((_a2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _a2.self) && ev.target !== elementRef.value)
  387. return;
  388. clear();
  389. if ((_b2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _b2.prevent)
  390. ev.preventDefault();
  391. if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
  392. ev.stopPropagation();
  393. posStart = {
  394. x: ev.x,
  395. y: ev.y
  396. };
  397. startTimestamp = ev.timeStamp;
  398. timeout = setTimeout(
  399. () => {
  400. hasLongPressed = true;
  401. handler(ev);
  402. },
  403. (_d = options == null ? void 0 : options.delay) != null ? _d : DEFAULT_DELAY
  404. );
  405. }
  406. function onMove(ev) {
  407. var _a2, _b2, _c, _d;
  408. if (((_a2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _a2.self) && ev.target !== elementRef.value)
  409. return;
  410. if (!posStart || (options == null ? void 0 : options.distanceThreshold) === false)
  411. return;
  412. if ((_b2 = options == null ? void 0 : options.modifiers) == null ? void 0 : _b2.prevent)
  413. ev.preventDefault();
  414. if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
  415. ev.stopPropagation();
  416. const dx = ev.x - posStart.x;
  417. const dy = ev.y - posStart.y;
  418. const distance = Math.sqrt(dx * dx + dy * dy);
  419. if (distance >= ((_d = options == null ? void 0 : options.distanceThreshold) != null ? _d : DEFAULT_THRESHOLD))
  420. clear();
  421. }
  422. const listenerOptions = {
  423. capture: (_a = options == null ? void 0 : options.modifiers) == null ? void 0 : _a.capture,
  424. once: (_b = options == null ? void 0 : options.modifiers) == null ? void 0 : _b.once
  425. };
  426. const cleanup = [
  427. useEventListener(elementRef, "pointerdown", onDown, listenerOptions),
  428. useEventListener(elementRef, "pointermove", onMove, listenerOptions),
  429. useEventListener(elementRef, ["pointerup", "pointerleave"], onRelease, listenerOptions)
  430. ];
  431. const stop = () => cleanup.forEach((fn) => fn());
  432. return stop;
  433. }
  434. function isFocusedElementEditable() {
  435. const { activeElement, body } = document;
  436. if (!activeElement)
  437. return false;
  438. if (activeElement === body)
  439. return false;
  440. switch (activeElement.tagName) {
  441. case "INPUT":
  442. case "TEXTAREA":
  443. return true;
  444. }
  445. return activeElement.hasAttribute("contenteditable");
  446. }
  447. function isTypedCharValid({
  448. keyCode,
  449. metaKey,
  450. ctrlKey,
  451. altKey
  452. }) {
  453. if (metaKey || ctrlKey || altKey)
  454. return false;
  455. if (keyCode >= 48 && keyCode <= 57)
  456. return true;
  457. if (keyCode >= 65 && keyCode <= 90)
  458. return true;
  459. if (keyCode >= 97 && keyCode <= 122)
  460. return true;
  461. return false;
  462. }
  463. function onStartTyping(callback, options = {}) {
  464. const { document: document2 = defaultDocument } = options;
  465. const keydown = (event) => {
  466. if (!isFocusedElementEditable() && isTypedCharValid(event)) {
  467. callback(event);
  468. }
  469. };
  470. if (document2)
  471. useEventListener(document2, "keydown", keydown, { passive: true });
  472. }
  473. function templateRef(key, initialValue = null) {
  474. const instance = vue.getCurrentInstance();
  475. let _trigger = () => {
  476. };
  477. const element = vue.customRef((track, trigger) => {
  478. _trigger = trigger;
  479. return {
  480. get() {
  481. var _a, _b;
  482. track();
  483. return (_b = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.$refs[key]) != null ? _b : initialValue;
  484. },
  485. set() {
  486. }
  487. };
  488. });
  489. shared.tryOnMounted(_trigger);
  490. vue.onUpdated(_trigger);
  491. return element;
  492. }
  493. function useMounted() {
  494. const isMounted = vue.ref(false);
  495. const instance = vue.getCurrentInstance();
  496. if (instance) {
  497. vue.onMounted(() => {
  498. isMounted.value = true;
  499. }, instance);
  500. }
  501. return isMounted;
  502. }
  503. function useSupported(callback) {
  504. const isMounted = useMounted();
  505. return vue.computed(() => {
  506. isMounted.value;
  507. return Boolean(callback());
  508. });
  509. }
  510. function useMutationObserver(target, callback, options = {}) {
  511. const { window = defaultWindow, ...mutationOptions } = options;
  512. let observer;
  513. const isSupported = useSupported(() => window && "MutationObserver" in window);
  514. const cleanup = () => {
  515. if (observer) {
  516. observer.disconnect();
  517. observer = void 0;
  518. }
  519. };
  520. const targets = vue.computed(() => {
  521. const value = shared.toValue(target);
  522. const items = (Array.isArray(value) ? value : [value]).map(unrefElement).filter(shared.notNullish);
  523. return new Set(items);
  524. });
  525. const stopWatch = vue.watch(
  526. () => targets.value,
  527. (targets2) => {
  528. cleanup();
  529. if (isSupported.value && targets2.size) {
  530. observer = new MutationObserver(callback);
  531. targets2.forEach((el) => observer.observe(el, mutationOptions));
  532. }
  533. },
  534. { immediate: true, flush: "post" }
  535. );
  536. const takeRecords = () => {
  537. return observer == null ? void 0 : observer.takeRecords();
  538. };
  539. const stop = () => {
  540. stopWatch();
  541. cleanup();
  542. };
  543. shared.tryOnScopeDispose(stop);
  544. return {
  545. isSupported,
  546. stop,
  547. takeRecords
  548. };
  549. }
  550. function useActiveElement(options = {}) {
  551. var _a;
  552. const {
  553. window = defaultWindow,
  554. deep = true,
  555. triggerOnRemoval = false
  556. } = options;
  557. const document = (_a = options.document) != null ? _a : window == null ? void 0 : window.document;
  558. const getDeepActiveElement = () => {
  559. var _a2;
  560. let element = document == null ? void 0 : document.activeElement;
  561. if (deep) {
  562. while (element == null ? void 0 : element.shadowRoot)
  563. element = (_a2 = element == null ? void 0 : element.shadowRoot) == null ? void 0 : _a2.activeElement;
  564. }
  565. return element;
  566. };
  567. const activeElement = vue.ref();
  568. const trigger = () => {
  569. activeElement.value = getDeepActiveElement();
  570. };
  571. if (window) {
  572. useEventListener(window, "blur", (event) => {
  573. if (event.relatedTarget !== null)
  574. return;
  575. trigger();
  576. }, true);
  577. useEventListener(window, "focus", trigger, true);
  578. }
  579. if (triggerOnRemoval) {
  580. useMutationObserver(document, (mutations) => {
  581. mutations.filter((m) => m.removedNodes.length).map((n) => Array.from(n.removedNodes)).flat().forEach((node) => {
  582. if (node === activeElement.value)
  583. trigger();
  584. });
  585. }, {
  586. childList: true,
  587. subtree: true
  588. });
  589. }
  590. trigger();
  591. return activeElement;
  592. }
  593. function useRafFn(fn, options = {}) {
  594. const {
  595. immediate = true,
  596. fpsLimit = void 0,
  597. window = defaultWindow
  598. } = options;
  599. const isActive = vue.ref(false);
  600. const intervalLimit = fpsLimit ? 1e3 / fpsLimit : null;
  601. let previousFrameTimestamp = 0;
  602. let rafId = null;
  603. function loop(timestamp) {
  604. if (!isActive.value || !window)
  605. return;
  606. if (!previousFrameTimestamp)
  607. previousFrameTimestamp = timestamp;
  608. const delta = timestamp - previousFrameTimestamp;
  609. if (intervalLimit && delta < intervalLimit) {
  610. rafId = window.requestAnimationFrame(loop);
  611. return;
  612. }
  613. previousFrameTimestamp = timestamp;
  614. fn({ delta, timestamp });
  615. rafId = window.requestAnimationFrame(loop);
  616. }
  617. function resume() {
  618. if (!isActive.value && window) {
  619. isActive.value = true;
  620. previousFrameTimestamp = 0;
  621. rafId = window.requestAnimationFrame(loop);
  622. }
  623. }
  624. function pause() {
  625. isActive.value = false;
  626. if (rafId != null && window) {
  627. window.cancelAnimationFrame(rafId);
  628. rafId = null;
  629. }
  630. }
  631. if (immediate)
  632. resume();
  633. shared.tryOnScopeDispose(pause);
  634. return {
  635. isActive: vue.readonly(isActive),
  636. pause,
  637. resume
  638. };
  639. }
  640. function useAnimate(target, keyframes, options) {
  641. let config;
  642. let animateOptions;
  643. if (shared.isObject(options)) {
  644. config = options;
  645. animateOptions = shared.objectOmit(options, ["window", "immediate", "commitStyles", "persist", "onReady", "onError"]);
  646. } else {
  647. config = { duration: options };
  648. animateOptions = options;
  649. }
  650. const {
  651. window = defaultWindow,
  652. immediate = true,
  653. commitStyles,
  654. persist,
  655. playbackRate: _playbackRate = 1,
  656. onReady,
  657. onError = (e) => {
  658. console.error(e);
  659. }
  660. } = config;
  661. const isSupported = useSupported(() => window && HTMLElement && "animate" in HTMLElement.prototype);
  662. const animate = vue.shallowRef(void 0);
  663. const store = vue.shallowReactive({
  664. startTime: null,
  665. currentTime: null,
  666. timeline: null,
  667. playbackRate: _playbackRate,
  668. pending: false,
  669. playState: immediate ? "idle" : "paused",
  670. replaceState: "active"
  671. });
  672. const pending = vue.computed(() => store.pending);
  673. const playState = vue.computed(() => store.playState);
  674. const replaceState = vue.computed(() => store.replaceState);
  675. const startTime = vue.computed({
  676. get() {
  677. return store.startTime;
  678. },
  679. set(value) {
  680. store.startTime = value;
  681. if (animate.value)
  682. animate.value.startTime = value;
  683. }
  684. });
  685. const currentTime = vue.computed({
  686. get() {
  687. return store.currentTime;
  688. },
  689. set(value) {
  690. store.currentTime = value;
  691. if (animate.value) {
  692. animate.value.currentTime = value;
  693. syncResume();
  694. }
  695. }
  696. });
  697. const timeline = vue.computed({
  698. get() {
  699. return store.timeline;
  700. },
  701. set(value) {
  702. store.timeline = value;
  703. if (animate.value)
  704. animate.value.timeline = value;
  705. }
  706. });
  707. const playbackRate = vue.computed({
  708. get() {
  709. return store.playbackRate;
  710. },
  711. set(value) {
  712. store.playbackRate = value;
  713. if (animate.value)
  714. animate.value.playbackRate = value;
  715. }
  716. });
  717. const play = () => {
  718. if (animate.value) {
  719. try {
  720. animate.value.play();
  721. syncResume();
  722. } catch (e) {
  723. syncPause();
  724. onError(e);
  725. }
  726. } else {
  727. update();
  728. }
  729. };
  730. const pause = () => {
  731. var _a;
  732. try {
  733. (_a = animate.value) == null ? void 0 : _a.pause();
  734. syncPause();
  735. } catch (e) {
  736. onError(e);
  737. }
  738. };
  739. const reverse = () => {
  740. var _a;
  741. if (!animate.value)
  742. update();
  743. try {
  744. (_a = animate.value) == null ? void 0 : _a.reverse();
  745. syncResume();
  746. } catch (e) {
  747. syncPause();
  748. onError(e);
  749. }
  750. };
  751. const finish = () => {
  752. var _a;
  753. try {
  754. (_a = animate.value) == null ? void 0 : _a.finish();
  755. syncPause();
  756. } catch (e) {
  757. onError(e);
  758. }
  759. };
  760. const cancel = () => {
  761. var _a;
  762. try {
  763. (_a = animate.value) == null ? void 0 : _a.cancel();
  764. syncPause();
  765. } catch (e) {
  766. onError(e);
  767. }
  768. };
  769. vue.watch(() => unrefElement(target), (el) => {
  770. if (el)
  771. update();
  772. });
  773. vue.watch(() => keyframes, (value) => {
  774. if (animate.value)
  775. update();
  776. if (!unrefElement(target) && animate.value) {
  777. animate.value.effect = new KeyframeEffect(
  778. unrefElement(target),
  779. shared.toValue(value),
  780. animateOptions
  781. );
  782. }
  783. }, { deep: true });
  784. shared.tryOnMounted(() => update(true), false);
  785. shared.tryOnScopeDispose(cancel);
  786. function update(init) {
  787. const el = unrefElement(target);
  788. if (!isSupported.value || !el)
  789. return;
  790. if (!animate.value)
  791. animate.value = el.animate(shared.toValue(keyframes), animateOptions);
  792. if (persist)
  793. animate.value.persist();
  794. if (_playbackRate !== 1)
  795. animate.value.playbackRate = _playbackRate;
  796. if (init && !immediate)
  797. animate.value.pause();
  798. else
  799. syncResume();
  800. onReady == null ? void 0 : onReady(animate.value);
  801. }
  802. useEventListener(animate, ["cancel", "finish", "remove"], syncPause);
  803. useEventListener(animate, "finish", () => {
  804. var _a;
  805. if (commitStyles)
  806. (_a = animate.value) == null ? void 0 : _a.commitStyles();
  807. });
  808. const { resume: resumeRef, pause: pauseRef } = useRafFn(() => {
  809. if (!animate.value)
  810. return;
  811. store.pending = animate.value.pending;
  812. store.playState = animate.value.playState;
  813. store.replaceState = animate.value.replaceState;
  814. store.startTime = animate.value.startTime;
  815. store.currentTime = animate.value.currentTime;
  816. store.timeline = animate.value.timeline;
  817. store.playbackRate = animate.value.playbackRate;
  818. }, { immediate: false });
  819. function syncResume() {
  820. if (isSupported.value)
  821. resumeRef();
  822. }
  823. function syncPause() {
  824. if (isSupported.value && window)
  825. window.requestAnimationFrame(pauseRef);
  826. }
  827. return {
  828. isSupported,
  829. animate,
  830. // actions
  831. play,
  832. pause,
  833. reverse,
  834. finish,
  835. cancel,
  836. // state
  837. pending,
  838. playState,
  839. replaceState,
  840. startTime,
  841. currentTime,
  842. timeline,
  843. playbackRate
  844. };
  845. }
  846. function useAsyncQueue(tasks, options) {
  847. const {
  848. interrupt = true,
  849. onError = shared.noop,
  850. onFinished = shared.noop,
  851. signal
  852. } = options || {};
  853. const promiseState = {
  854. aborted: "aborted",
  855. fulfilled: "fulfilled",
  856. pending: "pending",
  857. rejected: "rejected"
  858. };
  859. const initialResult = Array.from(Array.from({ length: tasks.length }), () => ({ state: promiseState.pending, data: null }));
  860. const result = vue.reactive(initialResult);
  861. const activeIndex = vue.ref(-1);
  862. if (!tasks || tasks.length === 0) {
  863. onFinished();
  864. return {
  865. activeIndex,
  866. result
  867. };
  868. }
  869. function updateResult(state, res) {
  870. activeIndex.value++;
  871. result[activeIndex.value].data = res;
  872. result[activeIndex.value].state = state;
  873. }
  874. tasks.reduce((prev, curr) => {
  875. return prev.then((prevRes) => {
  876. var _a;
  877. if (signal == null ? void 0 : signal.aborted) {
  878. updateResult(promiseState.aborted, new Error("aborted"));
  879. return;
  880. }
  881. if (((_a = result[activeIndex.value]) == null ? void 0 : _a.state) === promiseState.rejected && interrupt) {
  882. onFinished();
  883. return;
  884. }
  885. const done = curr(prevRes).then((currentRes) => {
  886. updateResult(promiseState.fulfilled, currentRes);
  887. if (activeIndex.value === tasks.length - 1)
  888. onFinished();
  889. return currentRes;
  890. });
  891. if (!signal)
  892. return done;
  893. return Promise.race([done, whenAborted(signal)]);
  894. }).catch((e) => {
  895. if (signal == null ? void 0 : signal.aborted) {
  896. updateResult(promiseState.aborted, e);
  897. return e;
  898. }
  899. updateResult(promiseState.rejected, e);
  900. onError();
  901. return e;
  902. });
  903. }, Promise.resolve());
  904. return {
  905. activeIndex,
  906. result
  907. };
  908. }
  909. function whenAborted(signal) {
  910. return new Promise((resolve, reject) => {
  911. const error = new Error("aborted");
  912. if (signal.aborted)
  913. reject(error);
  914. else
  915. signal.addEventListener("abort", () => reject(error), { once: true });
  916. });
  917. }
  918. function useAsyncState(promise, initialState, options) {
  919. const {
  920. immediate = true,
  921. delay = 0,
  922. onError = shared.noop,
  923. onSuccess = shared.noop,
  924. resetOnExecute = true,
  925. shallow = true,
  926. throwError
  927. } = options != null ? options : {};
  928. const state = shallow ? vue.shallowRef(initialState) : vue.ref(initialState);
  929. const isReady = vue.ref(false);
  930. const isLoading = vue.ref(false);
  931. const error = vue.shallowRef(void 0);
  932. async function execute(delay2 = 0, ...args) {
  933. if (resetOnExecute)
  934. state.value = initialState;
  935. error.value = void 0;
  936. isReady.value = false;
  937. isLoading.value = true;
  938. if (delay2 > 0)
  939. await shared.promiseTimeout(delay2);
  940. const _promise = typeof promise === "function" ? promise(...args) : promise;
  941. try {
  942. const data = await _promise;
  943. state.value = data;
  944. isReady.value = true;
  945. onSuccess(data);
  946. } catch (e) {
  947. error.value = e;
  948. onError(e);
  949. if (throwError)
  950. throw e;
  951. } finally {
  952. isLoading.value = false;
  953. }
  954. return state.value;
  955. }
  956. if (immediate)
  957. execute(delay);
  958. const shell = {
  959. state,
  960. isReady,
  961. isLoading,
  962. error,
  963. execute
  964. };
  965. function waitUntilIsLoaded() {
  966. return new Promise((resolve, reject) => {
  967. shared.until(isLoading).toBe(false).then(() => resolve(shell)).catch(reject);
  968. });
  969. }
  970. return {
  971. ...shell,
  972. then(onFulfilled, onRejected) {
  973. return waitUntilIsLoaded().then(onFulfilled, onRejected);
  974. }
  975. };
  976. }
  977. const defaults = {
  978. array: (v) => JSON.stringify(v),
  979. object: (v) => JSON.stringify(v),
  980. set: (v) => JSON.stringify(Array.from(v)),
  981. map: (v) => JSON.stringify(Object.fromEntries(v)),
  982. null: () => ""
  983. };
  984. function getDefaultSerialization(target) {
  985. if (!target)
  986. return defaults.null;
  987. if (target instanceof Map)
  988. return defaults.map;
  989. else if (target instanceof Set)
  990. return defaults.set;
  991. else if (Array.isArray(target))
  992. return defaults.array;
  993. else
  994. return defaults.object;
  995. }
  996. function useBase64(target, options) {
  997. const base64 = vue.ref("");
  998. const promise = vue.ref();
  999. function execute() {
  1000. if (!shared.isClient)
  1001. return;
  1002. promise.value = new Promise((resolve, reject) => {
  1003. try {
  1004. const _target = shared.toValue(target);
  1005. if (_target == null) {
  1006. resolve("");
  1007. } else if (typeof _target === "string") {
  1008. resolve(blobToBase64(new Blob([_target], { type: "text/plain" })));
  1009. } else if (_target instanceof Blob) {
  1010. resolve(blobToBase64(_target));
  1011. } else if (_target instanceof ArrayBuffer) {
  1012. resolve(window.btoa(String.fromCharCode(...new Uint8Array(_target))));
  1013. } else if (_target instanceof HTMLCanvasElement) {
  1014. resolve(_target.toDataURL(options == null ? void 0 : options.type, options == null ? void 0 : options.quality));
  1015. } else if (_target instanceof HTMLImageElement) {
  1016. const img = _target.cloneNode(false);
  1017. img.crossOrigin = "Anonymous";
  1018. imgLoaded(img).then(() => {
  1019. const canvas = document.createElement("canvas");
  1020. const ctx = canvas.getContext("2d");
  1021. canvas.width = img.width;
  1022. canvas.height = img.height;
  1023. ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
  1024. resolve(canvas.toDataURL(options == null ? void 0 : options.type, options == null ? void 0 : options.quality));
  1025. }).catch(reject);
  1026. } else if (typeof _target === "object") {
  1027. const _serializeFn = (options == null ? void 0 : options.serializer) || getDefaultSerialization(_target);
  1028. const serialized = _serializeFn(_target);
  1029. return resolve(blobToBase64(new Blob([serialized], { type: "application/json" })));
  1030. } else {
  1031. reject(new Error("target is unsupported types"));
  1032. }
  1033. } catch (error) {
  1034. reject(error);
  1035. }
  1036. });
  1037. promise.value.then((res) => base64.value = res);
  1038. return promise.value;
  1039. }
  1040. if (vue.isRef(target) || typeof target === "function")
  1041. vue.watch(target, execute, { immediate: true });
  1042. else
  1043. execute();
  1044. return {
  1045. base64,
  1046. promise,
  1047. execute
  1048. };
  1049. }
  1050. function imgLoaded(img) {
  1051. return new Promise((resolve, reject) => {
  1052. if (!img.complete) {
  1053. img.onload = () => {
  1054. resolve();
  1055. };
  1056. img.onerror = reject;
  1057. } else {
  1058. resolve();
  1059. }
  1060. });
  1061. }
  1062. function blobToBase64(blob) {
  1063. return new Promise((resolve, reject) => {
  1064. const fr = new FileReader();
  1065. fr.onload = (e) => {
  1066. resolve(e.target.result);
  1067. };
  1068. fr.onerror = reject;
  1069. fr.readAsDataURL(blob);
  1070. });
  1071. }
  1072. function useBattery(options = {}) {
  1073. const { navigator = defaultNavigator } = options;
  1074. const events = ["chargingchange", "chargingtimechange", "dischargingtimechange", "levelchange"];
  1075. const isSupported = useSupported(() => navigator && "getBattery" in navigator && typeof navigator.getBattery === "function");
  1076. const charging = vue.ref(false);
  1077. const chargingTime = vue.ref(0);
  1078. const dischargingTime = vue.ref(0);
  1079. const level = vue.ref(1);
  1080. let battery;
  1081. function updateBatteryInfo() {
  1082. charging.value = this.charging;
  1083. chargingTime.value = this.chargingTime || 0;
  1084. dischargingTime.value = this.dischargingTime || 0;
  1085. level.value = this.level;
  1086. }
  1087. if (isSupported.value) {
  1088. navigator.getBattery().then((_battery) => {
  1089. battery = _battery;
  1090. updateBatteryInfo.call(battery);
  1091. useEventListener(battery, events, updateBatteryInfo, { passive: true });
  1092. });
  1093. }
  1094. return {
  1095. isSupported,
  1096. charging,
  1097. chargingTime,
  1098. dischargingTime,
  1099. level
  1100. };
  1101. }
  1102. function useBluetooth(options) {
  1103. let {
  1104. acceptAllDevices = false
  1105. } = options || {};
  1106. const {
  1107. filters = void 0,
  1108. optionalServices = void 0,
  1109. navigator = defaultNavigator
  1110. } = options || {};
  1111. const isSupported = useSupported(() => navigator && "bluetooth" in navigator);
  1112. const device = vue.shallowRef(void 0);
  1113. const error = vue.shallowRef(null);
  1114. vue.watch(device, () => {
  1115. connectToBluetoothGATTServer();
  1116. });
  1117. async function requestDevice() {
  1118. if (!isSupported.value)
  1119. return;
  1120. error.value = null;
  1121. if (filters && filters.length > 0)
  1122. acceptAllDevices = false;
  1123. try {
  1124. device.value = await (navigator == null ? void 0 : navigator.bluetooth.requestDevice({
  1125. acceptAllDevices,
  1126. filters,
  1127. optionalServices
  1128. }));
  1129. } catch (err) {
  1130. error.value = err;
  1131. }
  1132. }
  1133. const server = vue.ref();
  1134. const isConnected = vue.computed(() => {
  1135. var _a;
  1136. return ((_a = server.value) == null ? void 0 : _a.connected) || false;
  1137. });
  1138. async function connectToBluetoothGATTServer() {
  1139. error.value = null;
  1140. if (device.value && device.value.gatt) {
  1141. device.value.addEventListener("gattserverdisconnected", () => {
  1142. });
  1143. try {
  1144. server.value = await device.value.gatt.connect();
  1145. } catch (err) {
  1146. error.value = err;
  1147. }
  1148. }
  1149. }
  1150. shared.tryOnMounted(() => {
  1151. var _a;
  1152. if (device.value)
  1153. (_a = device.value.gatt) == null ? void 0 : _a.connect();
  1154. });
  1155. shared.tryOnScopeDispose(() => {
  1156. var _a;
  1157. if (device.value)
  1158. (_a = device.value.gatt) == null ? void 0 : _a.disconnect();
  1159. });
  1160. return {
  1161. isSupported,
  1162. isConnected,
  1163. // Device:
  1164. device,
  1165. requestDevice,
  1166. // Server:
  1167. server,
  1168. // Errors:
  1169. error
  1170. };
  1171. }
  1172. function useMediaQuery(query, options = {}) {
  1173. const { window = defaultWindow } = options;
  1174. const isSupported = useSupported(() => window && "matchMedia" in window && typeof window.matchMedia === "function");
  1175. let mediaQuery;
  1176. const matches = vue.ref(false);
  1177. const handler = (event) => {
  1178. matches.value = event.matches;
  1179. };
  1180. const cleanup = () => {
  1181. if (!mediaQuery)
  1182. return;
  1183. if ("removeEventListener" in mediaQuery)
  1184. mediaQuery.removeEventListener("change", handler);
  1185. else
  1186. mediaQuery.removeListener(handler);
  1187. };
  1188. const stopWatch = vue.watchEffect(() => {
  1189. if (!isSupported.value)
  1190. return;
  1191. cleanup();
  1192. mediaQuery = window.matchMedia(shared.toValue(query));
  1193. if ("addEventListener" in mediaQuery)
  1194. mediaQuery.addEventListener("change", handler);
  1195. else
  1196. mediaQuery.addListener(handler);
  1197. matches.value = mediaQuery.matches;
  1198. });
  1199. shared.tryOnScopeDispose(() => {
  1200. stopWatch();
  1201. cleanup();
  1202. mediaQuery = void 0;
  1203. });
  1204. return matches;
  1205. }
  1206. const breakpointsTailwind = {
  1207. "sm": 640,
  1208. "md": 768,
  1209. "lg": 1024,
  1210. "xl": 1280,
  1211. "2xl": 1536
  1212. };
  1213. const breakpointsBootstrapV5 = {
  1214. xs: 0,
  1215. sm: 576,
  1216. md: 768,
  1217. lg: 992,
  1218. xl: 1200,
  1219. xxl: 1400
  1220. };
  1221. const breakpointsVuetifyV2 = {
  1222. xs: 0,
  1223. sm: 600,
  1224. md: 960,
  1225. lg: 1264,
  1226. xl: 1904
  1227. };
  1228. const breakpointsVuetifyV3 = {
  1229. xs: 0,
  1230. sm: 600,
  1231. md: 960,
  1232. lg: 1280,
  1233. xl: 1920,
  1234. xxl: 2560
  1235. };
  1236. const breakpointsVuetify = breakpointsVuetifyV2;
  1237. const breakpointsAntDesign = {
  1238. xs: 480,
  1239. sm: 576,
  1240. md: 768,
  1241. lg: 992,
  1242. xl: 1200,
  1243. xxl: 1600
  1244. };
  1245. const breakpointsQuasar = {
  1246. xs: 0,
  1247. sm: 600,
  1248. md: 1024,
  1249. lg: 1440,
  1250. xl: 1920
  1251. };
  1252. const breakpointsSematic = {
  1253. mobileS: 320,
  1254. mobileM: 375,
  1255. mobileL: 425,
  1256. tablet: 768,
  1257. laptop: 1024,
  1258. laptopL: 1440,
  1259. desktop4K: 2560
  1260. };
  1261. const breakpointsMasterCss = {
  1262. "3xs": 360,
  1263. "2xs": 480,
  1264. "xs": 600,
  1265. "sm": 768,
  1266. "md": 1024,
  1267. "lg": 1280,
  1268. "xl": 1440,
  1269. "2xl": 1600,
  1270. "3xl": 1920,
  1271. "4xl": 2560
  1272. };
  1273. const breakpointsPrimeFlex = {
  1274. sm: 576,
  1275. md: 768,
  1276. lg: 992,
  1277. xl: 1200
  1278. };
  1279. const breakpointsElement = {
  1280. xs: 0,
  1281. sm: 768,
  1282. md: 992,
  1283. lg: 1200,
  1284. xl: 1920
  1285. };
  1286. function useBreakpoints(breakpoints, options = {}) {
  1287. function getValue(k, delta) {
  1288. let v = shared.toValue(breakpoints[shared.toValue(k)]);
  1289. if (delta != null)
  1290. v = shared.increaseWithUnit(v, delta);
  1291. if (typeof v === "number")
  1292. v = `${v}px`;
  1293. return v;
  1294. }
  1295. const { window = defaultWindow, strategy = "min-width" } = options;
  1296. function match(query) {
  1297. if (!window)
  1298. return false;
  1299. return window.matchMedia(query).matches;
  1300. }
  1301. const greaterOrEqual = (k) => {
  1302. return useMediaQuery(() => `(min-width: ${getValue(k)})`, options);
  1303. };
  1304. const smallerOrEqual = (k) => {
  1305. return useMediaQuery(() => `(max-width: ${getValue(k)})`, options);
  1306. };
  1307. const shortcutMethods = Object.keys(breakpoints).reduce((shortcuts, k) => {
  1308. Object.defineProperty(shortcuts, k, {
  1309. get: () => strategy === "min-width" ? greaterOrEqual(k) : smallerOrEqual(k),
  1310. enumerable: true,
  1311. configurable: true
  1312. });
  1313. return shortcuts;
  1314. }, {});
  1315. function current() {
  1316. const points = Object.keys(breakpoints).map((i) => [i, greaterOrEqual(i)]);
  1317. return vue.computed(() => points.filter(([, v]) => v.value).map(([k]) => k));
  1318. }
  1319. return Object.assign(shortcutMethods, {
  1320. greaterOrEqual,
  1321. smallerOrEqual,
  1322. greater(k) {
  1323. return useMediaQuery(() => `(min-width: ${getValue(k, 0.1)})`, options);
  1324. },
  1325. smaller(k) {
  1326. return useMediaQuery(() => `(max-width: ${getValue(k, -0.1)})`, options);
  1327. },
  1328. between(a, b) {
  1329. return useMediaQuery(() => `(min-width: ${getValue(a)}) and (max-width: ${getValue(b, -0.1)})`, options);
  1330. },
  1331. isGreater(k) {
  1332. return match(`(min-width: ${getValue(k, 0.1)})`);
  1333. },
  1334. isGreaterOrEqual(k) {
  1335. return match(`(min-width: ${getValue(k)})`);
  1336. },
  1337. isSmaller(k) {
  1338. return match(`(max-width: ${getValue(k, -0.1)})`);
  1339. },
  1340. isSmallerOrEqual(k) {
  1341. return match(`(max-width: ${getValue(k)})`);
  1342. },
  1343. isInBetween(a, b) {
  1344. return match(`(min-width: ${getValue(a)}) and (max-width: ${getValue(b, -0.1)})`);
  1345. },
  1346. current,
  1347. active() {
  1348. const bps = current();
  1349. return vue.computed(() => bps.value.length === 0 ? "" : bps.value.at(-1));
  1350. }
  1351. });
  1352. }
  1353. function useBroadcastChannel(options) {
  1354. const {
  1355. name,
  1356. window = defaultWindow
  1357. } = options;
  1358. const isSupported = useSupported(() => window && "BroadcastChannel" in window);
  1359. const isClosed = vue.ref(false);
  1360. const channel = vue.ref();
  1361. const data = vue.ref();
  1362. const error = vue.shallowRef(null);
  1363. const post = (data2) => {
  1364. if (channel.value)
  1365. channel.value.postMessage(data2);
  1366. };
  1367. const close = () => {
  1368. if (channel.value)
  1369. channel.value.close();
  1370. isClosed.value = true;
  1371. };
  1372. if (isSupported.value) {
  1373. shared.tryOnMounted(() => {
  1374. error.value = null;
  1375. channel.value = new BroadcastChannel(name);
  1376. channel.value.addEventListener("message", (e) => {
  1377. data.value = e.data;
  1378. }, { passive: true });
  1379. channel.value.addEventListener("messageerror", (e) => {
  1380. error.value = e;
  1381. }, { passive: true });
  1382. channel.value.addEventListener("close", () => {
  1383. isClosed.value = true;
  1384. });
  1385. });
  1386. }
  1387. shared.tryOnScopeDispose(() => {
  1388. close();
  1389. });
  1390. return {
  1391. isSupported,
  1392. channel,
  1393. data,
  1394. post,
  1395. close,
  1396. error,
  1397. isClosed
  1398. };
  1399. }
  1400. const WRITABLE_PROPERTIES = [
  1401. "hash",
  1402. "host",
  1403. "hostname",
  1404. "href",
  1405. "pathname",
  1406. "port",
  1407. "protocol",
  1408. "search"
  1409. ];
  1410. function useBrowserLocation(options = {}) {
  1411. const { window = defaultWindow } = options;
  1412. const refs = Object.fromEntries(
  1413. WRITABLE_PROPERTIES.map((key) => [key, vue.ref()])
  1414. );
  1415. for (const [key, ref2] of shared.objectEntries(refs)) {
  1416. vue.watch(ref2, (value) => {
  1417. if (!(window == null ? void 0 : window.location) || window.location[key] === value)
  1418. return;
  1419. window.location[key] = value;
  1420. });
  1421. }
  1422. const buildState = (trigger) => {
  1423. var _a;
  1424. const { state: state2, length } = (window == null ? void 0 : window.history) || {};
  1425. const { origin } = (window == null ? void 0 : window.location) || {};
  1426. for (const key of WRITABLE_PROPERTIES)
  1427. refs[key].value = (_a = window == null ? void 0 : window.location) == null ? void 0 : _a[key];
  1428. return vue.reactive({
  1429. trigger,
  1430. state: state2,
  1431. length,
  1432. origin,
  1433. ...refs
  1434. });
  1435. };
  1436. const state = vue.ref(buildState("load"));
  1437. if (window) {
  1438. useEventListener(window, "popstate", () => state.value = buildState("popstate"), { passive: true });
  1439. useEventListener(window, "hashchange", () => state.value = buildState("hashchange"), { passive: true });
  1440. }
  1441. return state;
  1442. }
  1443. function useCached(refValue, comparator = (a, b) => a === b, watchOptions) {
  1444. const cachedValue = vue.ref(refValue.value);
  1445. vue.watch(() => refValue.value, (value) => {
  1446. if (!comparator(value, cachedValue.value))
  1447. cachedValue.value = value;
  1448. }, watchOptions);
  1449. return cachedValue;
  1450. }
  1451. function usePermission(permissionDesc, options = {}) {
  1452. const {
  1453. controls = false,
  1454. navigator = defaultNavigator
  1455. } = options;
  1456. const isSupported = useSupported(() => navigator && "permissions" in navigator);
  1457. const permissionStatus = vue.shallowRef();
  1458. const desc = typeof permissionDesc === "string" ? { name: permissionDesc } : permissionDesc;
  1459. const state = vue.shallowRef();
  1460. const update = () => {
  1461. var _a, _b;
  1462. state.value = (_b = (_a = permissionStatus.value) == null ? void 0 : _a.state) != null ? _b : "prompt";
  1463. };
  1464. useEventListener(permissionStatus, "change", update);
  1465. const query = shared.createSingletonPromise(async () => {
  1466. if (!isSupported.value)
  1467. return;
  1468. if (!permissionStatus.value) {
  1469. try {
  1470. permissionStatus.value = await navigator.permissions.query(desc);
  1471. } catch (e) {
  1472. permissionStatus.value = void 0;
  1473. } finally {
  1474. update();
  1475. }
  1476. }
  1477. if (controls)
  1478. return vue.toRaw(permissionStatus.value);
  1479. });
  1480. query();
  1481. if (controls) {
  1482. return {
  1483. state,
  1484. isSupported,
  1485. query
  1486. };
  1487. } else {
  1488. return state;
  1489. }
  1490. }
  1491. function useClipboard(options = {}) {
  1492. const {
  1493. navigator = defaultNavigator,
  1494. read = false,
  1495. source,
  1496. copiedDuring = 1500,
  1497. legacy = false
  1498. } = options;
  1499. const isClipboardApiSupported = useSupported(() => navigator && "clipboard" in navigator);
  1500. const permissionRead = usePermission("clipboard-read");
  1501. const permissionWrite = usePermission("clipboard-write");
  1502. const isSupported = vue.computed(() => isClipboardApiSupported.value || legacy);
  1503. const text = vue.ref("");
  1504. const copied = vue.ref(false);
  1505. const timeout = shared.useTimeoutFn(() => copied.value = false, copiedDuring);
  1506. function updateText() {
  1507. if (isClipboardApiSupported.value && isAllowed(permissionRead.value)) {
  1508. navigator.clipboard.readText().then((value) => {
  1509. text.value = value;
  1510. });
  1511. } else {
  1512. text.value = legacyRead();
  1513. }
  1514. }
  1515. if (isSupported.value && read)
  1516. useEventListener(["copy", "cut"], updateText);
  1517. async function copy(value = shared.toValue(source)) {
  1518. if (isSupported.value && value != null) {
  1519. if (isClipboardApiSupported.value && isAllowed(permissionWrite.value))
  1520. await navigator.clipboard.writeText(value);
  1521. else
  1522. legacyCopy(value);
  1523. text.value = value;
  1524. copied.value = true;
  1525. timeout.start();
  1526. }
  1527. }
  1528. function legacyCopy(value) {
  1529. const ta = document.createElement("textarea");
  1530. ta.value = value != null ? value : "";
  1531. ta.style.position = "absolute";
  1532. ta.style.opacity = "0";
  1533. document.body.appendChild(ta);
  1534. ta.select();
  1535. document.execCommand("copy");
  1536. ta.remove();
  1537. }
  1538. function legacyRead() {
  1539. var _a, _b, _c;
  1540. return (_c = (_b = (_a = document == null ? void 0 : document.getSelection) == null ? void 0 : _a.call(document)) == null ? void 0 : _b.toString()) != null ? _c : "";
  1541. }
  1542. function isAllowed(status) {
  1543. return status === "granted" || status === "prompt";
  1544. }
  1545. return {
  1546. isSupported,
  1547. text,
  1548. copied,
  1549. copy
  1550. };
  1551. }
  1552. function useClipboardItems(options = {}) {
  1553. const {
  1554. navigator = defaultNavigator,
  1555. read = false,
  1556. source,
  1557. copiedDuring = 1500
  1558. } = options;
  1559. const isSupported = useSupported(() => navigator && "clipboard" in navigator);
  1560. const content = vue.ref([]);
  1561. const copied = vue.ref(false);
  1562. const timeout = shared.useTimeoutFn(() => copied.value = false, copiedDuring);
  1563. function updateContent() {
  1564. if (isSupported.value) {
  1565. navigator.clipboard.read().then((items) => {
  1566. content.value = items;
  1567. });
  1568. }
  1569. }
  1570. if (isSupported.value && read)
  1571. useEventListener(["copy", "cut"], updateContent);
  1572. async function copy(value = shared.toValue(source)) {
  1573. if (isSupported.value && value != null) {
  1574. await navigator.clipboard.write(value);
  1575. content.value = value;
  1576. copied.value = true;
  1577. timeout.start();
  1578. }
  1579. }
  1580. return {
  1581. isSupported,
  1582. content,
  1583. copied,
  1584. copy
  1585. };
  1586. }
  1587. function cloneFnJSON(source) {
  1588. return JSON.parse(JSON.stringify(source));
  1589. }
  1590. function useCloned(source, options = {}) {
  1591. const cloned = vue.ref({});
  1592. const {
  1593. manual,
  1594. clone = cloneFnJSON,
  1595. // watch options
  1596. deep = true,
  1597. immediate = true
  1598. } = options;
  1599. function sync() {
  1600. cloned.value = clone(shared.toValue(source));
  1601. }
  1602. if (!manual && (vue.isRef(source) || typeof source === "function")) {
  1603. vue.watch(source, sync, {
  1604. ...options,
  1605. deep,
  1606. immediate
  1607. });
  1608. } else {
  1609. sync();
  1610. }
  1611. return { cloned, sync };
  1612. }
  1613. const _global = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  1614. const globalKey = "__vueuse_ssr_handlers__";
  1615. const handlers = /* @__PURE__ */ getHandlers();
  1616. function getHandlers() {
  1617. if (!(globalKey in _global))
  1618. _global[globalKey] = _global[globalKey] || {};
  1619. return _global[globalKey];
  1620. }
  1621. function getSSRHandler(key, fallback) {
  1622. return handlers[key] || fallback;
  1623. }
  1624. function setSSRHandler(key, fn) {
  1625. handlers[key] = fn;
  1626. }
  1627. function usePreferredDark(options) {
  1628. return useMediaQuery("(prefers-color-scheme: dark)", options);
  1629. }
  1630. function guessSerializerType(rawInit) {
  1631. return rawInit == null ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
  1632. }
  1633. const StorageSerializers = {
  1634. boolean: {
  1635. read: (v) => v === "true",
  1636. write: (v) => String(v)
  1637. },
  1638. object: {
  1639. read: (v) => JSON.parse(v),
  1640. write: (v) => JSON.stringify(v)
  1641. },
  1642. number: {
  1643. read: (v) => Number.parseFloat(v),
  1644. write: (v) => String(v)
  1645. },
  1646. any: {
  1647. read: (v) => v,
  1648. write: (v) => String(v)
  1649. },
  1650. string: {
  1651. read: (v) => v,
  1652. write: (v) => String(v)
  1653. },
  1654. map: {
  1655. read: (v) => new Map(JSON.parse(v)),
  1656. write: (v) => JSON.stringify(Array.from(v.entries()))
  1657. },
  1658. set: {
  1659. read: (v) => new Set(JSON.parse(v)),
  1660. write: (v) => JSON.stringify(Array.from(v))
  1661. },
  1662. date: {
  1663. read: (v) => new Date(v),
  1664. write: (v) => v.toISOString()
  1665. }
  1666. };
  1667. const customStorageEventName = "vueuse-storage";
  1668. function useStorage(key, defaults, storage, options = {}) {
  1669. var _a;
  1670. const {
  1671. flush = "pre",
  1672. deep = true,
  1673. listenToStorageChanges = true,
  1674. writeDefaults = true,
  1675. mergeDefaults = false,
  1676. shallow,
  1677. window = defaultWindow,
  1678. eventFilter,
  1679. onError = (e) => {
  1680. console.error(e);
  1681. },
  1682. initOnMounted
  1683. } = options;
  1684. const data = (shallow ? vue.shallowRef : vue.ref)(typeof defaults === "function" ? defaults() : defaults);
  1685. if (!storage) {
  1686. try {
  1687. storage = getSSRHandler("getDefaultStorage", () => {
  1688. var _a2;
  1689. return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
  1690. })();
  1691. } catch (e) {
  1692. onError(e);
  1693. }
  1694. }
  1695. if (!storage)
  1696. return data;
  1697. const rawInit = shared.toValue(defaults);
  1698. const type = guessSerializerType(rawInit);
  1699. const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
  1700. const { pause: pauseWatch, resume: resumeWatch } = shared.pausableWatch(
  1701. data,
  1702. () => write(data.value),
  1703. { flush, deep, eventFilter }
  1704. );
  1705. if (window && listenToStorageChanges) {
  1706. shared.tryOnMounted(() => {
  1707. if (storage instanceof Storage)
  1708. useEventListener(window, "storage", update);
  1709. else
  1710. useEventListener(window, customStorageEventName, updateFromCustomEvent);
  1711. if (initOnMounted)
  1712. update();
  1713. });
  1714. }
  1715. if (!initOnMounted)
  1716. update();
  1717. function dispatchWriteEvent(oldValue, newValue) {
  1718. if (window) {
  1719. const payload = {
  1720. key,
  1721. oldValue,
  1722. newValue,
  1723. storageArea: storage
  1724. };
  1725. window.dispatchEvent(storage instanceof Storage ? new StorageEvent("storage", payload) : new CustomEvent(customStorageEventName, {
  1726. detail: payload
  1727. }));
  1728. }
  1729. }
  1730. function write(v) {
  1731. try {
  1732. const oldValue = storage.getItem(key);
  1733. if (v == null) {
  1734. dispatchWriteEvent(oldValue, null);
  1735. storage.removeItem(key);
  1736. } else {
  1737. const serialized = serializer.write(v);
  1738. if (oldValue !== serialized) {
  1739. storage.setItem(key, serialized);
  1740. dispatchWriteEvent(oldValue, serialized);
  1741. }
  1742. }
  1743. } catch (e) {
  1744. onError(e);
  1745. }
  1746. }
  1747. function read(event) {
  1748. const rawValue = event ? event.newValue : storage.getItem(key);
  1749. if (rawValue == null) {
  1750. if (writeDefaults && rawInit != null)
  1751. storage.setItem(key, serializer.write(rawInit));
  1752. return rawInit;
  1753. } else if (!event && mergeDefaults) {
  1754. const value = serializer.read(rawValue);
  1755. if (typeof mergeDefaults === "function")
  1756. return mergeDefaults(value, rawInit);
  1757. else if (type === "object" && !Array.isArray(value))
  1758. return { ...rawInit, ...value };
  1759. return value;
  1760. } else if (typeof rawValue !== "string") {
  1761. return rawValue;
  1762. } else {
  1763. return serializer.read(rawValue);
  1764. }
  1765. }
  1766. function update(event) {
  1767. if (event && event.storageArea !== storage)
  1768. return;
  1769. if (event && event.key == null) {
  1770. data.value = rawInit;
  1771. return;
  1772. }
  1773. if (event && event.key !== key)
  1774. return;
  1775. pauseWatch();
  1776. try {
  1777. if ((event == null ? void 0 : event.newValue) !== serializer.write(data.value))
  1778. data.value = read(event);
  1779. } catch (e) {
  1780. onError(e);
  1781. } finally {
  1782. if (event)
  1783. vue.nextTick(resumeWatch);
  1784. else
  1785. resumeWatch();
  1786. }
  1787. }
  1788. function updateFromCustomEvent(event) {
  1789. update(event.detail);
  1790. }
  1791. return data;
  1792. }
  1793. const CSS_DISABLE_TRANS = "*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
  1794. function useColorMode(options = {}) {
  1795. const {
  1796. selector = "html",
  1797. attribute = "class",
  1798. initialValue = "auto",
  1799. window = defaultWindow,
  1800. storage,
  1801. storageKey = "vueuse-color-scheme",
  1802. listenToStorageChanges = true,
  1803. storageRef,
  1804. emitAuto,
  1805. disableTransition = true
  1806. } = options;
  1807. const modes = {
  1808. auto: "",
  1809. light: "light",
  1810. dark: "dark",
  1811. ...options.modes || {}
  1812. };
  1813. const preferredDark = usePreferredDark({ window });
  1814. const system = vue.computed(() => preferredDark.value ? "dark" : "light");
  1815. const store = storageRef || (storageKey == null ? shared.toRef(initialValue) : useStorage(storageKey, initialValue, storage, { window, listenToStorageChanges }));
  1816. const state = vue.computed(() => store.value === "auto" ? system.value : store.value);
  1817. const updateHTMLAttrs = getSSRHandler(
  1818. "updateHTMLAttrs",
  1819. (selector2, attribute2, value) => {
  1820. const el = typeof selector2 === "string" ? window == null ? void 0 : window.document.querySelector(selector2) : unrefElement(selector2);
  1821. if (!el)
  1822. return;
  1823. const classesToAdd = /* @__PURE__ */ new Set();
  1824. const classesToRemove = /* @__PURE__ */ new Set();
  1825. let attributeToChange = null;
  1826. if (attribute2 === "class") {
  1827. const current = value.split(/\s/g);
  1828. Object.values(modes).flatMap((i) => (i || "").split(/\s/g)).filter(Boolean).forEach((v) => {
  1829. if (current.includes(v))
  1830. classesToAdd.add(v);
  1831. else
  1832. classesToRemove.add(v);
  1833. });
  1834. } else {
  1835. attributeToChange = { key: attribute2, value };
  1836. }
  1837. if (classesToAdd.size === 0 && classesToRemove.size === 0 && attributeToChange === null)
  1838. return;
  1839. let style;
  1840. if (disableTransition) {
  1841. style = window.document.createElement("style");
  1842. style.appendChild(document.createTextNode(CSS_DISABLE_TRANS));
  1843. window.document.head.appendChild(style);
  1844. }
  1845. for (const c of classesToAdd) {
  1846. el.classList.add(c);
  1847. }
  1848. for (const c of classesToRemove) {
  1849. el.classList.remove(c);
  1850. }
  1851. if (attributeToChange) {
  1852. el.setAttribute(attributeToChange.key, attributeToChange.value);
  1853. }
  1854. if (disableTransition) {
  1855. window.getComputedStyle(style).opacity;
  1856. document.head.removeChild(style);
  1857. }
  1858. }
  1859. );
  1860. function defaultOnChanged(mode) {
  1861. var _a;
  1862. updateHTMLAttrs(selector, attribute, (_a = modes[mode]) != null ? _a : mode);
  1863. }
  1864. function onChanged(mode) {
  1865. if (options.onChanged)
  1866. options.onChanged(mode, defaultOnChanged);
  1867. else
  1868. defaultOnChanged(mode);
  1869. }
  1870. vue.watch(state, onChanged, { flush: "post", immediate: true });
  1871. shared.tryOnMounted(() => onChanged(state.value));
  1872. const auto = vue.computed({
  1873. get() {
  1874. return emitAuto ? store.value : state.value;
  1875. },
  1876. set(v) {
  1877. store.value = v;
  1878. }
  1879. });
  1880. return Object.assign(auto, { store, system, state });
  1881. }
  1882. function useConfirmDialog(revealed = vue.ref(false)) {
  1883. const confirmHook = shared.createEventHook();
  1884. const cancelHook = shared.createEventHook();
  1885. const revealHook = shared.createEventHook();
  1886. let _resolve = shared.noop;
  1887. const reveal = (data) => {
  1888. revealHook.trigger(data);
  1889. revealed.value = true;
  1890. return new Promise((resolve) => {
  1891. _resolve = resolve;
  1892. });
  1893. };
  1894. const confirm = (data) => {
  1895. revealed.value = false;
  1896. confirmHook.trigger(data);
  1897. _resolve({ data, isCanceled: false });
  1898. };
  1899. const cancel = (data) => {
  1900. revealed.value = false;
  1901. cancelHook.trigger(data);
  1902. _resolve({ data, isCanceled: true });
  1903. };
  1904. return {
  1905. isRevealed: vue.computed(() => revealed.value),
  1906. reveal,
  1907. confirm,
  1908. cancel,
  1909. onReveal: revealHook.on,
  1910. onConfirm: confirmHook.on,
  1911. onCancel: cancelHook.on
  1912. };
  1913. }
  1914. function useCssVar(prop, target, options = {}) {
  1915. const { window = defaultWindow, initialValue, observe = false } = options;
  1916. const variable = vue.ref(initialValue);
  1917. const elRef = vue.computed(() => {
  1918. var _a;
  1919. return unrefElement(target) || ((_a = window == null ? void 0 : window.document) == null ? void 0 : _a.documentElement);
  1920. });
  1921. function updateCssVar() {
  1922. var _a;
  1923. const key = shared.toValue(prop);
  1924. const el = shared.toValue(elRef);
  1925. if (el && window && key) {
  1926. const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
  1927. variable.value = value || initialValue;
  1928. }
  1929. }
  1930. if (observe) {
  1931. useMutationObserver(elRef, updateCssVar, {
  1932. attributeFilter: ["style", "class"],
  1933. window
  1934. });
  1935. }
  1936. vue.watch(
  1937. [elRef, () => shared.toValue(prop)],
  1938. (_, old) => {
  1939. if (old[0] && old[1])
  1940. old[0].style.removeProperty(old[1]);
  1941. updateCssVar();
  1942. },
  1943. { immediate: true }
  1944. );
  1945. vue.watch(
  1946. variable,
  1947. (val) => {
  1948. var _a;
  1949. const raw_prop = shared.toValue(prop);
  1950. if (((_a = elRef.value) == null ? void 0 : _a.style) && raw_prop) {
  1951. if (val == null)
  1952. elRef.value.style.removeProperty(raw_prop);
  1953. else
  1954. elRef.value.style.setProperty(raw_prop, val);
  1955. }
  1956. }
  1957. );
  1958. return variable;
  1959. }
  1960. function useCurrentElement(rootComponent) {
  1961. const vm = vue.getCurrentInstance();
  1962. const currentElement = shared.computedWithControl(
  1963. () => null,
  1964. () => rootComponent ? unrefElement(rootComponent) : vm.proxy.$el
  1965. );
  1966. vue.onUpdated(currentElement.trigger);
  1967. vue.onMounted(currentElement.trigger);
  1968. return currentElement;
  1969. }
  1970. function useCycleList(list, options) {
  1971. const state = vue.shallowRef(getInitialValue());
  1972. const listRef = shared.toRef(list);
  1973. const index = vue.computed({
  1974. get() {
  1975. var _a;
  1976. const targetList = listRef.value;
  1977. let index2 = (options == null ? void 0 : options.getIndexOf) ? options.getIndexOf(state.value, targetList) : targetList.indexOf(state.value);
  1978. if (index2 < 0)
  1979. index2 = (_a = options == null ? void 0 : options.fallbackIndex) != null ? _a : 0;
  1980. return index2;
  1981. },
  1982. set(v) {
  1983. set(v);
  1984. }
  1985. });
  1986. function set(i) {
  1987. const targetList = listRef.value;
  1988. const length = targetList.length;
  1989. const index2 = (i % length + length) % length;
  1990. const value = targetList[index2];
  1991. state.value = value;
  1992. return value;
  1993. }
  1994. function shift(delta = 1) {
  1995. return set(index.value + delta);
  1996. }
  1997. function next(n = 1) {
  1998. return shift(n);
  1999. }
  2000. function prev(n = 1) {
  2001. return shift(-n);
  2002. }
  2003. function getInitialValue() {
  2004. var _a, _b;
  2005. return (_b = shared.toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : shared.toValue(list)[0])) != null ? _b : void 0;
  2006. }
  2007. vue.watch(listRef, () => set(index.value));
  2008. return {
  2009. state,
  2010. index,
  2011. next,
  2012. prev,
  2013. go: set
  2014. };
  2015. }
  2016. function useDark(options = {}) {
  2017. const {
  2018. valueDark = "dark",
  2019. valueLight = ""
  2020. } = options;
  2021. const mode = useColorMode({
  2022. ...options,
  2023. onChanged: (mode2, defaultHandler) => {
  2024. var _a;
  2025. if (options.onChanged)
  2026. (_a = options.onChanged) == null ? void 0 : _a.call(options, mode2 === "dark", defaultHandler, mode2);
  2027. else
  2028. defaultHandler(mode2);
  2029. },
  2030. modes: {
  2031. dark: valueDark,
  2032. light: valueLight
  2033. }
  2034. });
  2035. const system = vue.computed(() => mode.system.value);
  2036. const isDark = vue.computed({
  2037. get() {
  2038. return mode.value === "dark";
  2039. },
  2040. set(v) {
  2041. const modeVal = v ? "dark" : "light";
  2042. if (system.value === modeVal)
  2043. mode.value = "auto";
  2044. else
  2045. mode.value = modeVal;
  2046. }
  2047. });
  2048. return isDark;
  2049. }
  2050. function fnBypass(v) {
  2051. return v;
  2052. }
  2053. function fnSetSource(source, value) {
  2054. return source.value = value;
  2055. }
  2056. function defaultDump(clone) {
  2057. return clone ? typeof clone === "function" ? clone : cloneFnJSON : fnBypass;
  2058. }
  2059. function defaultParse(clone) {
  2060. return clone ? typeof clone === "function" ? clone : cloneFnJSON : fnBypass;
  2061. }
  2062. function useManualRefHistory(source, options = {}) {
  2063. const {
  2064. clone = false,
  2065. dump = defaultDump(clone),
  2066. parse = defaultParse(clone),
  2067. setSource = fnSetSource
  2068. } = options;
  2069. function _createHistoryRecord() {
  2070. return vue.markRaw({
  2071. snapshot: dump(source.value),
  2072. timestamp: shared.timestamp()
  2073. });
  2074. }
  2075. const last = vue.ref(_createHistoryRecord());
  2076. const undoStack = vue.ref([]);
  2077. const redoStack = vue.ref([]);
  2078. const _setSource = (record) => {
  2079. setSource(source, parse(record.snapshot));
  2080. last.value = record;
  2081. };
  2082. const commit = () => {
  2083. undoStack.value.unshift(last.value);
  2084. last.value = _createHistoryRecord();
  2085. if (options.capacity && undoStack.value.length > options.capacity)
  2086. undoStack.value.splice(options.capacity, Number.POSITIVE_INFINITY);
  2087. if (redoStack.value.length)
  2088. redoStack.value.splice(0, redoStack.value.length);
  2089. };
  2090. const clear = () => {
  2091. undoStack.value.splice(0, undoStack.value.length);
  2092. redoStack.value.splice(0, redoStack.value.length);
  2093. };
  2094. const undo = () => {
  2095. const state = undoStack.value.shift();
  2096. if (state) {
  2097. redoStack.value.unshift(last.value);
  2098. _setSource(state);
  2099. }
  2100. };
  2101. const redo = () => {
  2102. const state = redoStack.value.shift();
  2103. if (state) {
  2104. undoStack.value.unshift(last.value);
  2105. _setSource(state);
  2106. }
  2107. };
  2108. const reset = () => {
  2109. _setSource(last.value);
  2110. };
  2111. const history = vue.computed(() => [last.value, ...undoStack.value]);
  2112. const canUndo = vue.computed(() => undoStack.value.length > 0);
  2113. const canRedo = vue.computed(() => redoStack.value.length > 0);
  2114. return {
  2115. source,
  2116. undoStack,
  2117. redoStack,
  2118. last,
  2119. history,
  2120. canUndo,
  2121. canRedo,
  2122. clear,
  2123. commit,
  2124. reset,
  2125. undo,
  2126. redo
  2127. };
  2128. }
  2129. function useRefHistory(source, options = {}) {
  2130. const {
  2131. deep = false,
  2132. flush = "pre",
  2133. eventFilter
  2134. } = options;
  2135. const {
  2136. eventFilter: composedFilter,
  2137. pause,
  2138. resume: resumeTracking,
  2139. isActive: isTracking
  2140. } = shared.pausableFilter(eventFilter);
  2141. const {
  2142. ignoreUpdates,
  2143. ignorePrevAsyncUpdates,
  2144. stop
  2145. } = shared.watchIgnorable(
  2146. source,
  2147. commit,
  2148. { deep, flush, eventFilter: composedFilter }
  2149. );
  2150. function setSource(source2, value) {
  2151. ignorePrevAsyncUpdates();
  2152. ignoreUpdates(() => {
  2153. source2.value = value;
  2154. });
  2155. }
  2156. const manualHistory = useManualRefHistory(source, { ...options, clone: options.clone || deep, setSource });
  2157. const { clear, commit: manualCommit } = manualHistory;
  2158. function commit() {
  2159. ignorePrevAsyncUpdates();
  2160. manualCommit();
  2161. }
  2162. function resume(commitNow) {
  2163. resumeTracking();
  2164. if (commitNow)
  2165. commit();
  2166. }
  2167. function batch(fn) {
  2168. let canceled = false;
  2169. const cancel = () => canceled = true;
  2170. ignoreUpdates(() => {
  2171. fn(cancel);
  2172. });
  2173. if (!canceled)
  2174. commit();
  2175. }
  2176. function dispose() {
  2177. stop();
  2178. clear();
  2179. }
  2180. return {
  2181. ...manualHistory,
  2182. isTracking,
  2183. pause,
  2184. resume,
  2185. commit,
  2186. batch,
  2187. dispose
  2188. };
  2189. }
  2190. function useDebouncedRefHistory(source, options = {}) {
  2191. const filter = options.debounce ? shared.debounceFilter(options.debounce) : void 0;
  2192. const history = useRefHistory(source, { ...options, eventFilter: filter });
  2193. return {
  2194. ...history
  2195. };
  2196. }
  2197. function useDeviceMotion(options = {}) {
  2198. const {
  2199. window = defaultWindow,
  2200. eventFilter = shared.bypassFilter
  2201. } = options;
  2202. const acceleration = vue.ref({ x: null, y: null, z: null });
  2203. const rotationRate = vue.ref({ alpha: null, beta: null, gamma: null });
  2204. const interval = vue.ref(0);
  2205. const accelerationIncludingGravity = vue.ref({
  2206. x: null,
  2207. y: null,
  2208. z: null
  2209. });
  2210. if (window) {
  2211. const onDeviceMotion = shared.createFilterWrapper(
  2212. eventFilter,
  2213. (event) => {
  2214. acceleration.value = event.acceleration;
  2215. accelerationIncludingGravity.value = event.accelerationIncludingGravity;
  2216. rotationRate.value = event.rotationRate;
  2217. interval.value = event.interval;
  2218. }
  2219. );
  2220. useEventListener(window, "devicemotion", onDeviceMotion);
  2221. }
  2222. return {
  2223. acceleration,
  2224. accelerationIncludingGravity,
  2225. rotationRate,
  2226. interval
  2227. };
  2228. }
  2229. function useDeviceOrientation(options = {}) {
  2230. const { window = defaultWindow } = options;
  2231. const isSupported = useSupported(() => window && "DeviceOrientationEvent" in window);
  2232. const isAbsolute = vue.ref(false);
  2233. const alpha = vue.ref(null);
  2234. const beta = vue.ref(null);
  2235. const gamma = vue.ref(null);
  2236. if (window && isSupported.value) {
  2237. useEventListener(window, "deviceorientation", (event) => {
  2238. isAbsolute.value = event.absolute;
  2239. alpha.value = event.alpha;
  2240. beta.value = event.beta;
  2241. gamma.value = event.gamma;
  2242. });
  2243. }
  2244. return {
  2245. isSupported,
  2246. isAbsolute,
  2247. alpha,
  2248. beta,
  2249. gamma
  2250. };
  2251. }
  2252. function useDevicePixelRatio(options = {}) {
  2253. const {
  2254. window = defaultWindow
  2255. } = options;
  2256. const pixelRatio = vue.ref(1);
  2257. if (window) {
  2258. let observe2 = function() {
  2259. pixelRatio.value = window.devicePixelRatio;
  2260. cleanup2();
  2261. media = window.matchMedia(`(resolution: ${pixelRatio.value}dppx)`);
  2262. media.addEventListener("change", observe2, { once: true });
  2263. }, cleanup2 = function() {
  2264. media == null ? void 0 : media.removeEventListener("change", observe2);
  2265. };
  2266. let media;
  2267. observe2();
  2268. shared.tryOnScopeDispose(cleanup2);
  2269. }
  2270. return { pixelRatio };
  2271. }
  2272. function useDevicesList(options = {}) {
  2273. const {
  2274. navigator = defaultNavigator,
  2275. requestPermissions = false,
  2276. constraints = { audio: true, video: true },
  2277. onUpdated
  2278. } = options;
  2279. const devices = vue.ref([]);
  2280. const videoInputs = vue.computed(() => devices.value.filter((i) => i.kind === "videoinput"));
  2281. const audioInputs = vue.computed(() => devices.value.filter((i) => i.kind === "audioinput"));
  2282. const audioOutputs = vue.computed(() => devices.value.filter((i) => i.kind === "audiooutput"));
  2283. const isSupported = useSupported(() => navigator && navigator.mediaDevices && navigator.mediaDevices.enumerateDevices);
  2284. const permissionGranted = vue.ref(false);
  2285. let stream;
  2286. async function update() {
  2287. if (!isSupported.value)
  2288. return;
  2289. devices.value = await navigator.mediaDevices.enumerateDevices();
  2290. onUpdated == null ? void 0 : onUpdated(devices.value);
  2291. if (stream) {
  2292. stream.getTracks().forEach((t) => t.stop());
  2293. stream = null;
  2294. }
  2295. }
  2296. async function ensurePermissions() {
  2297. if (!isSupported.value)
  2298. return false;
  2299. if (permissionGranted.value)
  2300. return true;
  2301. const { state, query } = usePermission("camera", { controls: true });
  2302. await query();
  2303. if (state.value !== "granted") {
  2304. let granted = true;
  2305. try {
  2306. stream = await navigator.mediaDevices.getUserMedia(constraints);
  2307. } catch (e) {
  2308. stream = null;
  2309. granted = false;
  2310. }
  2311. update();
  2312. permissionGranted.value = granted;
  2313. } else {
  2314. permissionGranted.value = true;
  2315. }
  2316. return permissionGranted.value;
  2317. }
  2318. if (isSupported.value) {
  2319. if (requestPermissions)
  2320. ensurePermissions();
  2321. useEventListener(navigator.mediaDevices, "devicechange", update);
  2322. update();
  2323. }
  2324. return {
  2325. devices,
  2326. ensurePermissions,
  2327. permissionGranted,
  2328. videoInputs,
  2329. audioInputs,
  2330. audioOutputs,
  2331. isSupported
  2332. };
  2333. }
  2334. function useDisplayMedia(options = {}) {
  2335. var _a;
  2336. const enabled = vue.ref((_a = options.enabled) != null ? _a : false);
  2337. const video = options.video;
  2338. const audio = options.audio;
  2339. const { navigator = defaultNavigator } = options;
  2340. const isSupported = useSupported(() => {
  2341. var _a2;
  2342. return (_a2 = navigator == null ? void 0 : navigator.mediaDevices) == null ? void 0 : _a2.getDisplayMedia;
  2343. });
  2344. const constraint = { audio, video };
  2345. const stream = vue.shallowRef();
  2346. async function _start() {
  2347. var _a2;
  2348. if (!isSupported.value || stream.value)
  2349. return;
  2350. stream.value = await navigator.mediaDevices.getDisplayMedia(constraint);
  2351. (_a2 = stream.value) == null ? void 0 : _a2.getTracks().forEach((t) => t.addEventListener("ended", stop));
  2352. return stream.value;
  2353. }
  2354. async function _stop() {
  2355. var _a2;
  2356. (_a2 = stream.value) == null ? void 0 : _a2.getTracks().forEach((t) => t.stop());
  2357. stream.value = void 0;
  2358. }
  2359. function stop() {
  2360. _stop();
  2361. enabled.value = false;
  2362. }
  2363. async function start() {
  2364. await _start();
  2365. if (stream.value)
  2366. enabled.value = true;
  2367. return stream.value;
  2368. }
  2369. vue.watch(
  2370. enabled,
  2371. (v) => {
  2372. if (v)
  2373. _start();
  2374. else
  2375. _stop();
  2376. },
  2377. { immediate: true }
  2378. );
  2379. return {
  2380. isSupported,
  2381. stream,
  2382. start,
  2383. stop,
  2384. enabled
  2385. };
  2386. }
  2387. function useDocumentVisibility(options = {}) {
  2388. const { document = defaultDocument } = options;
  2389. if (!document)
  2390. return vue.ref("visible");
  2391. const visibility = vue.ref(document.visibilityState);
  2392. useEventListener(document, "visibilitychange", () => {
  2393. visibility.value = document.visibilityState;
  2394. });
  2395. return visibility;
  2396. }
  2397. function useDraggable(target, options = {}) {
  2398. var _a, _b;
  2399. const {
  2400. pointerTypes,
  2401. preventDefault,
  2402. stopPropagation,
  2403. exact,
  2404. onMove,
  2405. onEnd,
  2406. onStart,
  2407. initialValue,
  2408. axis = "both",
  2409. draggingElement = defaultWindow,
  2410. containerElement,
  2411. handle: draggingHandle = target,
  2412. buttons = [0]
  2413. } = options;
  2414. const position = vue.ref(
  2415. (_a = shared.toValue(initialValue)) != null ? _a : { x: 0, y: 0 }
  2416. );
  2417. const pressedDelta = vue.ref();
  2418. const filterEvent = (e) => {
  2419. if (pointerTypes)
  2420. return pointerTypes.includes(e.pointerType);
  2421. return true;
  2422. };
  2423. const handleEvent = (e) => {
  2424. if (shared.toValue(preventDefault))
  2425. e.preventDefault();
  2426. if (shared.toValue(stopPropagation))
  2427. e.stopPropagation();
  2428. };
  2429. const start = (e) => {
  2430. var _a2;
  2431. if (!shared.toValue(buttons).includes(e.button))
  2432. return;
  2433. if (shared.toValue(options.disabled) || !filterEvent(e))
  2434. return;
  2435. if (shared.toValue(exact) && e.target !== shared.toValue(target))
  2436. return;
  2437. const container = shared.toValue(containerElement);
  2438. const containerRect = (_a2 = container == null ? void 0 : container.getBoundingClientRect) == null ? void 0 : _a2.call(container);
  2439. const targetRect = shared.toValue(target).getBoundingClientRect();
  2440. const pos = {
  2441. x: e.clientX - (container ? targetRect.left - containerRect.left + container.scrollLeft : targetRect.left),
  2442. y: e.clientY - (container ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
  2443. };
  2444. if ((onStart == null ? void 0 : onStart(pos, e)) === false)
  2445. return;
  2446. pressedDelta.value = pos;
  2447. handleEvent(e);
  2448. };
  2449. const move = (e) => {
  2450. if (shared.toValue(options.disabled) || !filterEvent(e))
  2451. return;
  2452. if (!pressedDelta.value)
  2453. return;
  2454. const container = shared.toValue(containerElement);
  2455. const targetRect = shared.toValue(target).getBoundingClientRect();
  2456. let { x, y } = position.value;
  2457. if (axis === "x" || axis === "both") {
  2458. x = e.clientX - pressedDelta.value.x;
  2459. if (container)
  2460. x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
  2461. }
  2462. if (axis === "y" || axis === "both") {
  2463. y = e.clientY - pressedDelta.value.y;
  2464. if (container)
  2465. y = Math.min(Math.max(0, y), container.scrollHeight - targetRect.height);
  2466. }
  2467. position.value = {
  2468. x,
  2469. y
  2470. };
  2471. onMove == null ? void 0 : onMove(position.value, e);
  2472. handleEvent(e);
  2473. };
  2474. const end = (e) => {
  2475. if (shared.toValue(options.disabled) || !filterEvent(e))
  2476. return;
  2477. if (!pressedDelta.value)
  2478. return;
  2479. pressedDelta.value = void 0;
  2480. onEnd == null ? void 0 : onEnd(position.value, e);
  2481. handleEvent(e);
  2482. };
  2483. if (shared.isClient) {
  2484. const config = { capture: (_b = options.capture) != null ? _b : true };
  2485. useEventListener(draggingHandle, "pointerdown", start, config);
  2486. useEventListener(draggingElement, "pointermove", move, config);
  2487. useEventListener(draggingElement, "pointerup", end, config);
  2488. }
  2489. return {
  2490. ...shared.toRefs(position),
  2491. position,
  2492. isDragging: vue.computed(() => !!pressedDelta.value),
  2493. style: vue.computed(
  2494. () => `left:${position.value.x}px;top:${position.value.y}px;`
  2495. )
  2496. };
  2497. }
  2498. function useDropZone(target, options = {}) {
  2499. var _a, _b;
  2500. const isOverDropZone = vue.ref(false);
  2501. const files = vue.shallowRef(null);
  2502. let counter = 0;
  2503. let isValid = true;
  2504. if (shared.isClient) {
  2505. const _options = typeof options === "function" ? { onDrop: options } : options;
  2506. const multiple = (_a = _options.multiple) != null ? _a : true;
  2507. const preventDefaultForUnhandled = (_b = _options.preventDefaultForUnhandled) != null ? _b : false;
  2508. const getFiles = (event) => {
  2509. var _a2, _b2;
  2510. const list = Array.from((_b2 = (_a2 = event.dataTransfer) == null ? void 0 : _a2.files) != null ? _b2 : []);
  2511. return list.length === 0 ? null : multiple ? list : [list[0]];
  2512. };
  2513. const checkDataTypes = (types) => {
  2514. if (_options.dataTypes) {
  2515. const dataTypes = vue.unref(_options.dataTypes);
  2516. return typeof dataTypes === "function" ? dataTypes(types) : dataTypes ? dataTypes.some((item) => types.includes(item)) : true;
  2517. }
  2518. return true;
  2519. };
  2520. const checkValidity = (event) => {
  2521. var _a2, _b2;
  2522. const items = Array.from((_b2 = (_a2 = event.dataTransfer) == null ? void 0 : _a2.items) != null ? _b2 : []);
  2523. const types = items.map((item) => item.type);
  2524. const dataTypesValid = checkDataTypes(types);
  2525. const multipleFilesValid = multiple || items.length <= 1;
  2526. return dataTypesValid && multipleFilesValid;
  2527. };
  2528. const handleDragEvent = (event, eventType) => {
  2529. var _a2, _b2, _c, _d;
  2530. isValid = checkValidity(event);
  2531. if (!isValid) {
  2532. if (preventDefaultForUnhandled) {
  2533. event.preventDefault();
  2534. }
  2535. if (event.dataTransfer) {
  2536. event.dataTransfer.dropEffect = "none";
  2537. }
  2538. return;
  2539. }
  2540. event.preventDefault();
  2541. if (event.dataTransfer) {
  2542. event.dataTransfer.dropEffect = "copy";
  2543. }
  2544. const currentFiles = getFiles(event);
  2545. switch (eventType) {
  2546. case "enter":
  2547. counter += 1;
  2548. isOverDropZone.value = true;
  2549. (_a2 = _options.onEnter) == null ? void 0 : _a2.call(_options, null, event);
  2550. break;
  2551. case "over":
  2552. (_b2 = _options.onOver) == null ? void 0 : _b2.call(_options, null, event);
  2553. break;
  2554. case "leave":
  2555. counter -= 1;
  2556. if (counter === 0)
  2557. isOverDropZone.value = false;
  2558. (_c = _options.onLeave) == null ? void 0 : _c.call(_options, null, event);
  2559. break;
  2560. case "drop":
  2561. counter = 0;
  2562. isOverDropZone.value = false;
  2563. if (isValid) {
  2564. files.value = currentFiles;
  2565. (_d = _options.onDrop) == null ? void 0 : _d.call(_options, currentFiles, event);
  2566. }
  2567. break;
  2568. }
  2569. };
  2570. useEventListener(target, "dragenter", (event) => handleDragEvent(event, "enter"));
  2571. useEventListener(target, "dragover", (event) => handleDragEvent(event, "over"));
  2572. useEventListener(target, "dragleave", (event) => handleDragEvent(event, "leave"));
  2573. useEventListener(target, "drop", (event) => handleDragEvent(event, "drop"));
  2574. }
  2575. return {
  2576. files,
  2577. isOverDropZone
  2578. };
  2579. }
  2580. function useResizeObserver(target, callback, options = {}) {
  2581. const { window = defaultWindow, ...observerOptions } = options;
  2582. let observer;
  2583. const isSupported = useSupported(() => window && "ResizeObserver" in window);
  2584. const cleanup = () => {
  2585. if (observer) {
  2586. observer.disconnect();
  2587. observer = void 0;
  2588. }
  2589. };
  2590. const targets = vue.computed(() => {
  2591. const _targets = shared.toValue(target);
  2592. return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
  2593. });
  2594. const stopWatch = vue.watch(
  2595. targets,
  2596. (els) => {
  2597. cleanup();
  2598. if (isSupported.value && window) {
  2599. observer = new ResizeObserver(callback);
  2600. for (const _el of els) {
  2601. if (_el)
  2602. observer.observe(_el, observerOptions);
  2603. }
  2604. }
  2605. },
  2606. { immediate: true, flush: "post" }
  2607. );
  2608. const stop = () => {
  2609. cleanup();
  2610. stopWatch();
  2611. };
  2612. shared.tryOnScopeDispose(stop);
  2613. return {
  2614. isSupported,
  2615. stop
  2616. };
  2617. }
  2618. function useElementBounding(target, options = {}) {
  2619. const {
  2620. reset = true,
  2621. windowResize = true,
  2622. windowScroll = true,
  2623. immediate = true,
  2624. updateTiming = "sync"
  2625. } = options;
  2626. const height = vue.ref(0);
  2627. const bottom = vue.ref(0);
  2628. const left = vue.ref(0);
  2629. const right = vue.ref(0);
  2630. const top = vue.ref(0);
  2631. const width = vue.ref(0);
  2632. const x = vue.ref(0);
  2633. const y = vue.ref(0);
  2634. function recalculate() {
  2635. const el = unrefElement(target);
  2636. if (!el) {
  2637. if (reset) {
  2638. height.value = 0;
  2639. bottom.value = 0;
  2640. left.value = 0;
  2641. right.value = 0;
  2642. top.value = 0;
  2643. width.value = 0;
  2644. x.value = 0;
  2645. y.value = 0;
  2646. }
  2647. return;
  2648. }
  2649. const rect = el.getBoundingClientRect();
  2650. height.value = rect.height;
  2651. bottom.value = rect.bottom;
  2652. left.value = rect.left;
  2653. right.value = rect.right;
  2654. top.value = rect.top;
  2655. width.value = rect.width;
  2656. x.value = rect.x;
  2657. y.value = rect.y;
  2658. }
  2659. function update() {
  2660. if (updateTiming === "sync")
  2661. recalculate();
  2662. else if (updateTiming === "next-frame")
  2663. requestAnimationFrame(() => recalculate());
  2664. }
  2665. useResizeObserver(target, update);
  2666. vue.watch(() => unrefElement(target), (ele) => !ele && update());
  2667. useMutationObserver(target, update, {
  2668. attributeFilter: ["style", "class"]
  2669. });
  2670. if (windowScroll)
  2671. useEventListener("scroll", update, { capture: true, passive: true });
  2672. if (windowResize)
  2673. useEventListener("resize", update, { passive: true });
  2674. shared.tryOnMounted(() => {
  2675. if (immediate)
  2676. update();
  2677. });
  2678. return {
  2679. height,
  2680. bottom,
  2681. left,
  2682. right,
  2683. top,
  2684. width,
  2685. x,
  2686. y,
  2687. update
  2688. };
  2689. }
  2690. function useElementByPoint(options) {
  2691. const {
  2692. x,
  2693. y,
  2694. document = defaultDocument,
  2695. multiple,
  2696. interval = "requestAnimationFrame",
  2697. immediate = true
  2698. } = options;
  2699. const isSupported = useSupported(() => {
  2700. if (shared.toValue(multiple))
  2701. return document && "elementsFromPoint" in document;
  2702. return document && "elementFromPoint" in document;
  2703. });
  2704. const element = vue.ref(null);
  2705. const cb = () => {
  2706. var _a, _b;
  2707. element.value = shared.toValue(multiple) ? (_a = document == null ? void 0 : document.elementsFromPoint(shared.toValue(x), shared.toValue(y))) != null ? _a : [] : (_b = document == null ? void 0 : document.elementFromPoint(shared.toValue(x), shared.toValue(y))) != null ? _b : null;
  2708. };
  2709. const controls = interval === "requestAnimationFrame" ? useRafFn(cb, { immediate }) : shared.useIntervalFn(cb, interval, { immediate });
  2710. return {
  2711. isSupported,
  2712. element,
  2713. ...controls
  2714. };
  2715. }
  2716. function useElementHover(el, options = {}) {
  2717. const {
  2718. delayEnter = 0,
  2719. delayLeave = 0,
  2720. window = defaultWindow
  2721. } = options;
  2722. const isHovered = vue.ref(false);
  2723. let timer;
  2724. const toggle = (entering) => {
  2725. const delay = entering ? delayEnter : delayLeave;
  2726. if (timer) {
  2727. clearTimeout(timer);
  2728. timer = void 0;
  2729. }
  2730. if (delay)
  2731. timer = setTimeout(() => isHovered.value = entering, delay);
  2732. else
  2733. isHovered.value = entering;
  2734. };
  2735. if (!window)
  2736. return isHovered;
  2737. useEventListener(el, "mouseenter", () => toggle(true), { passive: true });
  2738. useEventListener(el, "mouseleave", () => toggle(false), { passive: true });
  2739. return isHovered;
  2740. }
  2741. function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
  2742. const { window = defaultWindow, box = "content-box" } = options;
  2743. const isSVG = vue.computed(() => {
  2744. var _a, _b;
  2745. return (_b = (_a = unrefElement(target)) == null ? void 0 : _a.namespaceURI) == null ? void 0 : _b.includes("svg");
  2746. });
  2747. const width = vue.ref(initialSize.width);
  2748. const height = vue.ref(initialSize.height);
  2749. const { stop: stop1 } = useResizeObserver(
  2750. target,
  2751. ([entry]) => {
  2752. const boxSize = box === "border-box" ? entry.borderBoxSize : box === "content-box" ? entry.contentBoxSize : entry.devicePixelContentBoxSize;
  2753. if (window && isSVG.value) {
  2754. const $elem = unrefElement(target);
  2755. if ($elem) {
  2756. const rect = $elem.getBoundingClientRect();
  2757. width.value = rect.width;
  2758. height.value = rect.height;
  2759. }
  2760. } else {
  2761. if (boxSize) {
  2762. const formatBoxSize = Array.isArray(boxSize) ? boxSize : [boxSize];
  2763. width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
  2764. height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
  2765. } else {
  2766. width.value = entry.contentRect.width;
  2767. height.value = entry.contentRect.height;
  2768. }
  2769. }
  2770. },
  2771. options
  2772. );
  2773. shared.tryOnMounted(() => {
  2774. const ele = unrefElement(target);
  2775. if (ele) {
  2776. width.value = "offsetWidth" in ele ? ele.offsetWidth : initialSize.width;
  2777. height.value = "offsetHeight" in ele ? ele.offsetHeight : initialSize.height;
  2778. }
  2779. });
  2780. const stop2 = vue.watch(
  2781. () => unrefElement(target),
  2782. (ele) => {
  2783. width.value = ele ? initialSize.width : 0;
  2784. height.value = ele ? initialSize.height : 0;
  2785. }
  2786. );
  2787. function stop() {
  2788. stop1();
  2789. stop2();
  2790. }
  2791. return {
  2792. width,
  2793. height,
  2794. stop
  2795. };
  2796. }
  2797. function useIntersectionObserver(target, callback, options = {}) {
  2798. const {
  2799. root,
  2800. rootMargin = "0px",
  2801. threshold = 0,
  2802. window = defaultWindow,
  2803. immediate = true
  2804. } = options;
  2805. const isSupported = useSupported(() => window && "IntersectionObserver" in window);
  2806. const targets = vue.computed(() => {
  2807. const _target = shared.toValue(target);
  2808. return (Array.isArray(_target) ? _target : [_target]).map(unrefElement).filter(shared.notNullish);
  2809. });
  2810. let cleanup = shared.noop;
  2811. const isActive = vue.ref(immediate);
  2812. const stopWatch = isSupported.value ? vue.watch(
  2813. () => [targets.value, unrefElement(root), isActive.value],
  2814. ([targets2, root2]) => {
  2815. cleanup();
  2816. if (!isActive.value)
  2817. return;
  2818. if (!targets2.length)
  2819. return;
  2820. const observer = new IntersectionObserver(
  2821. callback,
  2822. {
  2823. root: unrefElement(root2),
  2824. rootMargin,
  2825. threshold
  2826. }
  2827. );
  2828. targets2.forEach((el) => el && observer.observe(el));
  2829. cleanup = () => {
  2830. observer.disconnect();
  2831. cleanup = shared.noop;
  2832. };
  2833. },
  2834. { immediate, flush: "post" }
  2835. ) : shared.noop;
  2836. const stop = () => {
  2837. cleanup();
  2838. stopWatch();
  2839. isActive.value = false;
  2840. };
  2841. shared.tryOnScopeDispose(stop);
  2842. return {
  2843. isSupported,
  2844. isActive,
  2845. pause() {
  2846. cleanup();
  2847. isActive.value = false;
  2848. },
  2849. resume() {
  2850. isActive.value = true;
  2851. },
  2852. stop
  2853. };
  2854. }
  2855. function useElementVisibility(element, options = {}) {
  2856. const { window = defaultWindow, scrollTarget, threshold = 0 } = options;
  2857. const elementIsVisible = vue.ref(false);
  2858. useIntersectionObserver(
  2859. element,
  2860. (intersectionObserverEntries) => {
  2861. let isIntersecting = elementIsVisible.value;
  2862. let latestTime = 0;
  2863. for (const entry of intersectionObserverEntries) {
  2864. if (entry.time >= latestTime) {
  2865. latestTime = entry.time;
  2866. isIntersecting = entry.isIntersecting;
  2867. }
  2868. }
  2869. elementIsVisible.value = isIntersecting;
  2870. },
  2871. {
  2872. root: scrollTarget,
  2873. window,
  2874. threshold
  2875. }
  2876. );
  2877. return elementIsVisible;
  2878. }
  2879. const events = /* @__PURE__ */ new Map();
  2880. function useEventBus(key) {
  2881. const scope = vue.getCurrentScope();
  2882. function on(listener) {
  2883. var _a;
  2884. const listeners = events.get(key) || /* @__PURE__ */ new Set();
  2885. listeners.add(listener);
  2886. events.set(key, listeners);
  2887. const _off = () => off(listener);
  2888. (_a = scope == null ? void 0 : scope.cleanups) == null ? void 0 : _a.push(_off);
  2889. return _off;
  2890. }
  2891. function once(listener) {
  2892. function _listener(...args) {
  2893. off(_listener);
  2894. listener(...args);
  2895. }
  2896. return on(_listener);
  2897. }
  2898. function off(listener) {
  2899. const listeners = events.get(key);
  2900. if (!listeners)
  2901. return;
  2902. listeners.delete(listener);
  2903. if (!listeners.size)
  2904. reset();
  2905. }
  2906. function reset() {
  2907. events.delete(key);
  2908. }
  2909. function emit(event, payload) {
  2910. var _a;
  2911. (_a = events.get(key)) == null ? void 0 : _a.forEach((v) => v(event, payload));
  2912. }
  2913. return { on, once, off, emit, reset };
  2914. }
  2915. function resolveNestedOptions$1(options) {
  2916. if (options === true)
  2917. return {};
  2918. return options;
  2919. }
  2920. function useEventSource(url, events = [], options = {}) {
  2921. const event = vue.ref(null);
  2922. const data = vue.ref(null);
  2923. const status = vue.ref("CONNECTING");
  2924. const eventSource = vue.ref(null);
  2925. const error = vue.shallowRef(null);
  2926. const urlRef = shared.toRef(url);
  2927. const lastEventId = vue.shallowRef(null);
  2928. let explicitlyClosed = false;
  2929. let retried = 0;
  2930. const {
  2931. withCredentials = false,
  2932. immediate = true
  2933. } = options;
  2934. const close = () => {
  2935. if (shared.isClient && eventSource.value) {
  2936. eventSource.value.close();
  2937. eventSource.value = null;
  2938. status.value = "CLOSED";
  2939. explicitlyClosed = true;
  2940. }
  2941. };
  2942. const _init = () => {
  2943. if (explicitlyClosed || typeof urlRef.value === "undefined")
  2944. return;
  2945. const es = new EventSource(urlRef.value, { withCredentials });
  2946. status.value = "CONNECTING";
  2947. eventSource.value = es;
  2948. es.onopen = () => {
  2949. status.value = "OPEN";
  2950. error.value = null;
  2951. };
  2952. es.onerror = (e) => {
  2953. status.value = "CLOSED";
  2954. error.value = e;
  2955. if (es.readyState === 2 && !explicitlyClosed && options.autoReconnect) {
  2956. es.close();
  2957. const {
  2958. retries = -1,
  2959. delay = 1e3,
  2960. onFailed
  2961. } = resolveNestedOptions$1(options.autoReconnect);
  2962. retried += 1;
  2963. if (typeof retries === "number" && (retries < 0 || retried < retries))
  2964. setTimeout(_init, delay);
  2965. else if (typeof retries === "function" && retries())
  2966. setTimeout(_init, delay);
  2967. else
  2968. onFailed == null ? void 0 : onFailed();
  2969. }
  2970. };
  2971. es.onmessage = (e) => {
  2972. event.value = null;
  2973. data.value = e.data;
  2974. lastEventId.value = e.lastEventId;
  2975. };
  2976. for (const event_name of events) {
  2977. useEventListener(es, event_name, (e) => {
  2978. event.value = event_name;
  2979. data.value = e.data || null;
  2980. });
  2981. }
  2982. };
  2983. const open = () => {
  2984. if (!shared.isClient)
  2985. return;
  2986. close();
  2987. explicitlyClosed = false;
  2988. retried = 0;
  2989. _init();
  2990. };
  2991. if (immediate)
  2992. vue.watch(urlRef, open, { immediate: true });
  2993. shared.tryOnScopeDispose(close);
  2994. return {
  2995. eventSource,
  2996. event,
  2997. data,
  2998. status,
  2999. error,
  3000. open,
  3001. close,
  3002. lastEventId
  3003. };
  3004. }
  3005. function useEyeDropper(options = {}) {
  3006. const { initialValue = "" } = options;
  3007. const isSupported = useSupported(() => typeof window !== "undefined" && "EyeDropper" in window);
  3008. const sRGBHex = vue.ref(initialValue);
  3009. async function open(openOptions) {
  3010. if (!isSupported.value)
  3011. return;
  3012. const eyeDropper = new window.EyeDropper();
  3013. const result = await eyeDropper.open(openOptions);
  3014. sRGBHex.value = result.sRGBHex;
  3015. return result;
  3016. }
  3017. return { isSupported, sRGBHex, open };
  3018. }
  3019. function useFavicon(newIcon = null, options = {}) {
  3020. const {
  3021. baseUrl = "",
  3022. rel = "icon",
  3023. document = defaultDocument
  3024. } = options;
  3025. const favicon = shared.toRef(newIcon);
  3026. const applyIcon = (icon) => {
  3027. const elements = document == null ? void 0 : document.head.querySelectorAll(`link[rel*="${rel}"]`);
  3028. if (!elements || elements.length === 0) {
  3029. const link = document == null ? void 0 : document.createElement("link");
  3030. if (link) {
  3031. link.rel = rel;
  3032. link.href = `${baseUrl}${icon}`;
  3033. link.type = `image/${icon.split(".").pop()}`;
  3034. document == null ? void 0 : document.head.append(link);
  3035. }
  3036. return;
  3037. }
  3038. elements == null ? void 0 : elements.forEach((el) => el.href = `${baseUrl}${icon}`);
  3039. };
  3040. vue.watch(
  3041. favicon,
  3042. (i, o) => {
  3043. if (typeof i === "string" && i !== o)
  3044. applyIcon(i);
  3045. },
  3046. { immediate: true }
  3047. );
  3048. return favicon;
  3049. }
  3050. const payloadMapping = {
  3051. json: "application/json",
  3052. text: "text/plain"
  3053. };
  3054. function isFetchOptions(obj) {
  3055. return obj && shared.containsProp(obj, "immediate", "refetch", "initialData", "timeout", "beforeFetch", "afterFetch", "onFetchError", "fetch", "updateDataOnError");
  3056. }
  3057. const reAbsolute = /^(?:[a-z][a-z\d+\-.]*:)?\/\//i;
  3058. function isAbsoluteURL(url) {
  3059. return reAbsolute.test(url);
  3060. }
  3061. function headersToObject(headers) {
  3062. if (typeof Headers !== "undefined" && headers instanceof Headers)
  3063. return Object.fromEntries(headers.entries());
  3064. return headers;
  3065. }
  3066. function combineCallbacks(combination, ...callbacks) {
  3067. if (combination === "overwrite") {
  3068. return async (ctx) => {
  3069. const callback = callbacks[callbacks.length - 1];
  3070. if (callback)
  3071. return { ...ctx, ...await callback(ctx) };
  3072. return ctx;
  3073. };
  3074. } else {
  3075. return async (ctx) => {
  3076. for (const callback of callbacks) {
  3077. if (callback)
  3078. ctx = { ...ctx, ...await callback(ctx) };
  3079. }
  3080. return ctx;
  3081. };
  3082. }
  3083. }
  3084. function createFetch(config = {}) {
  3085. const _combination = config.combination || "chain";
  3086. const _options = config.options || {};
  3087. const _fetchOptions = config.fetchOptions || {};
  3088. function useFactoryFetch(url, ...args) {
  3089. const computedUrl = vue.computed(() => {
  3090. const baseUrl = shared.toValue(config.baseUrl);
  3091. const targetUrl = shared.toValue(url);
  3092. return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
  3093. });
  3094. let options = _options;
  3095. let fetchOptions = _fetchOptions;
  3096. if (args.length > 0) {
  3097. if (isFetchOptions(args[0])) {
  3098. options = {
  3099. ...options,
  3100. ...args[0],
  3101. beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[0].beforeFetch),
  3102. afterFetch: combineCallbacks(_combination, _options.afterFetch, args[0].afterFetch),
  3103. onFetchError: combineCallbacks(_combination, _options.onFetchError, args[0].onFetchError)
  3104. };
  3105. } else {
  3106. fetchOptions = {
  3107. ...fetchOptions,
  3108. ...args[0],
  3109. headers: {
  3110. ...headersToObject(fetchOptions.headers) || {},
  3111. ...headersToObject(args[0].headers) || {}
  3112. }
  3113. };
  3114. }
  3115. }
  3116. if (args.length > 1 && isFetchOptions(args[1])) {
  3117. options = {
  3118. ...options,
  3119. ...args[1],
  3120. beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[1].beforeFetch),
  3121. afterFetch: combineCallbacks(_combination, _options.afterFetch, args[1].afterFetch),
  3122. onFetchError: combineCallbacks(_combination, _options.onFetchError, args[1].onFetchError)
  3123. };
  3124. }
  3125. return useFetch(computedUrl, fetchOptions, options);
  3126. }
  3127. return useFactoryFetch;
  3128. }
  3129. function useFetch(url, ...args) {
  3130. var _a;
  3131. const supportsAbort = typeof AbortController === "function";
  3132. let fetchOptions = {};
  3133. let options = {
  3134. immediate: true,
  3135. refetch: false,
  3136. timeout: 0,
  3137. updateDataOnError: false
  3138. };
  3139. const config = {
  3140. method: "GET",
  3141. type: "text",
  3142. payload: void 0
  3143. };
  3144. if (args.length > 0) {
  3145. if (isFetchOptions(args[0]))
  3146. options = { ...options, ...args[0] };
  3147. else
  3148. fetchOptions = args[0];
  3149. }
  3150. if (args.length > 1) {
  3151. if (isFetchOptions(args[1]))
  3152. options = { ...options, ...args[1] };
  3153. }
  3154. const {
  3155. fetch = (_a = defaultWindow) == null ? void 0 : _a.fetch,
  3156. initialData,
  3157. timeout
  3158. } = options;
  3159. const responseEvent = shared.createEventHook();
  3160. const errorEvent = shared.createEventHook();
  3161. const finallyEvent = shared.createEventHook();
  3162. const isFinished = vue.ref(false);
  3163. const isFetching = vue.ref(false);
  3164. const aborted = vue.ref(false);
  3165. const statusCode = vue.ref(null);
  3166. const response = vue.shallowRef(null);
  3167. const error = vue.shallowRef(null);
  3168. const data = vue.shallowRef(initialData || null);
  3169. const canAbort = vue.computed(() => supportsAbort && isFetching.value);
  3170. let controller;
  3171. let timer;
  3172. const abort = () => {
  3173. if (supportsAbort) {
  3174. controller == null ? void 0 : controller.abort();
  3175. controller = new AbortController();
  3176. controller.signal.onabort = () => aborted.value = true;
  3177. fetchOptions = {
  3178. ...fetchOptions,
  3179. signal: controller.signal
  3180. };
  3181. }
  3182. };
  3183. const loading = (isLoading) => {
  3184. isFetching.value = isLoading;
  3185. isFinished.value = !isLoading;
  3186. };
  3187. if (timeout)
  3188. timer = shared.useTimeoutFn(abort, timeout, { immediate: false });
  3189. let executeCounter = 0;
  3190. const execute = async (throwOnFailed = false) => {
  3191. var _a2, _b;
  3192. abort();
  3193. loading(true);
  3194. error.value = null;
  3195. statusCode.value = null;
  3196. aborted.value = false;
  3197. executeCounter += 1;
  3198. const currentExecuteCounter = executeCounter;
  3199. const defaultFetchOptions = {
  3200. method: config.method,
  3201. headers: {}
  3202. };
  3203. if (config.payload) {
  3204. const headers = headersToObject(defaultFetchOptions.headers);
  3205. const payload = shared.toValue(config.payload);
  3206. const proto = Object.getPrototypeOf(payload);
  3207. if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
  3208. config.payloadType = "json";
  3209. if (config.payloadType)
  3210. headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
  3211. defaultFetchOptions.body = config.payloadType === "json" ? JSON.stringify(payload) : payload;
  3212. }
  3213. let isCanceled = false;
  3214. const context = {
  3215. url: shared.toValue(url),
  3216. options: {
  3217. ...defaultFetchOptions,
  3218. ...fetchOptions
  3219. },
  3220. cancel: () => {
  3221. isCanceled = true;
  3222. }
  3223. };
  3224. if (options.beforeFetch)
  3225. Object.assign(context, await options.beforeFetch(context));
  3226. if (isCanceled || !fetch) {
  3227. loading(false);
  3228. return Promise.resolve(null);
  3229. }
  3230. let responseData = null;
  3231. if (timer)
  3232. timer.start();
  3233. return fetch(
  3234. context.url,
  3235. {
  3236. ...defaultFetchOptions,
  3237. ...context.options,
  3238. headers: {
  3239. ...headersToObject(defaultFetchOptions.headers),
  3240. ...headersToObject((_b = context.options) == null ? void 0 : _b.headers)
  3241. }
  3242. }
  3243. ).then(async (fetchResponse) => {
  3244. response.value = fetchResponse;
  3245. statusCode.value = fetchResponse.status;
  3246. responseData = await fetchResponse.clone()[config.type]();
  3247. if (!fetchResponse.ok) {
  3248. data.value = initialData || null;
  3249. throw new Error(fetchResponse.statusText);
  3250. }
  3251. if (options.afterFetch) {
  3252. ({ data: responseData } = await options.afterFetch({
  3253. data: responseData,
  3254. response: fetchResponse
  3255. }));
  3256. }
  3257. data.value = responseData;
  3258. responseEvent.trigger(fetchResponse);
  3259. return fetchResponse;
  3260. }).catch(async (fetchError) => {
  3261. let errorData = fetchError.message || fetchError.name;
  3262. if (options.onFetchError) {
  3263. ({ error: errorData, data: responseData } = await options.onFetchError({
  3264. data: responseData,
  3265. error: fetchError,
  3266. response: response.value
  3267. }));
  3268. }
  3269. error.value = errorData;
  3270. if (options.updateDataOnError)
  3271. data.value = responseData;
  3272. errorEvent.trigger(fetchError);
  3273. if (throwOnFailed)
  3274. throw fetchError;
  3275. return null;
  3276. }).finally(() => {
  3277. if (currentExecuteCounter === executeCounter)
  3278. loading(false);
  3279. if (timer)
  3280. timer.stop();
  3281. finallyEvent.trigger(null);
  3282. });
  3283. };
  3284. const refetch = shared.toRef(options.refetch);
  3285. vue.watch(
  3286. [
  3287. refetch,
  3288. shared.toRef(url)
  3289. ],
  3290. ([refetch2]) => refetch2 && execute(),
  3291. { deep: true }
  3292. );
  3293. const shell = {
  3294. isFinished: vue.readonly(isFinished),
  3295. isFetching: vue.readonly(isFetching),
  3296. statusCode,
  3297. response,
  3298. error,
  3299. data,
  3300. canAbort,
  3301. aborted,
  3302. abort,
  3303. execute,
  3304. onFetchResponse: responseEvent.on,
  3305. onFetchError: errorEvent.on,
  3306. onFetchFinally: finallyEvent.on,
  3307. // method
  3308. get: setMethod("GET"),
  3309. put: setMethod("PUT"),
  3310. post: setMethod("POST"),
  3311. delete: setMethod("DELETE"),
  3312. patch: setMethod("PATCH"),
  3313. head: setMethod("HEAD"),
  3314. options: setMethod("OPTIONS"),
  3315. // type
  3316. json: setType("json"),
  3317. text: setType("text"),
  3318. blob: setType("blob"),
  3319. arrayBuffer: setType("arrayBuffer"),
  3320. formData: setType("formData")
  3321. };
  3322. function setMethod(method) {
  3323. return (payload, payloadType) => {
  3324. if (!isFetching.value) {
  3325. config.method = method;
  3326. config.payload = payload;
  3327. config.payloadType = payloadType;
  3328. if (vue.isRef(config.payload)) {
  3329. vue.watch(
  3330. [
  3331. refetch,
  3332. shared.toRef(config.payload)
  3333. ],
  3334. ([refetch2]) => refetch2 && execute(),
  3335. { deep: true }
  3336. );
  3337. }
  3338. return {
  3339. ...shell,
  3340. then(onFulfilled, onRejected) {
  3341. return waitUntilFinished().then(onFulfilled, onRejected);
  3342. }
  3343. };
  3344. }
  3345. return void 0;
  3346. };
  3347. }
  3348. function waitUntilFinished() {
  3349. return new Promise((resolve, reject) => {
  3350. shared.until(isFinished).toBe(true).then(() => resolve(shell)).catch(reject);
  3351. });
  3352. }
  3353. function setType(type) {
  3354. return () => {
  3355. if (!isFetching.value) {
  3356. config.type = type;
  3357. return {
  3358. ...shell,
  3359. then(onFulfilled, onRejected) {
  3360. return waitUntilFinished().then(onFulfilled, onRejected);
  3361. }
  3362. };
  3363. }
  3364. return void 0;
  3365. };
  3366. }
  3367. if (options.immediate)
  3368. Promise.resolve().then(() => execute());
  3369. return {
  3370. ...shell,
  3371. then(onFulfilled, onRejected) {
  3372. return waitUntilFinished().then(onFulfilled, onRejected);
  3373. }
  3374. };
  3375. }
  3376. function joinPaths(start, end) {
  3377. if (!start.endsWith("/") && !end.startsWith("/")) {
  3378. return `${start}/${end}`;
  3379. }
  3380. if (start.endsWith("/") && end.startsWith("/")) {
  3381. return `${start.slice(0, -1)}${end}`;
  3382. }
  3383. return `${start}${end}`;
  3384. }
  3385. const DEFAULT_OPTIONS = {
  3386. multiple: true,
  3387. accept: "*",
  3388. reset: false,
  3389. directory: false
  3390. };
  3391. function useFileDialog(options = {}) {
  3392. const {
  3393. document = defaultDocument
  3394. } = options;
  3395. const files = vue.ref(null);
  3396. const { on: onChange, trigger: changeTrigger } = shared.createEventHook();
  3397. const { on: onCancel, trigger: cancelTrigger } = shared.createEventHook();
  3398. let input;
  3399. if (document) {
  3400. input = document.createElement("input");
  3401. input.type = "file";
  3402. input.onchange = (event) => {
  3403. const result = event.target;
  3404. files.value = result.files;
  3405. changeTrigger(files.value);
  3406. };
  3407. input.oncancel = () => {
  3408. cancelTrigger();
  3409. };
  3410. }
  3411. const reset = () => {
  3412. files.value = null;
  3413. if (input && input.value) {
  3414. input.value = "";
  3415. changeTrigger(null);
  3416. }
  3417. };
  3418. const open = (localOptions) => {
  3419. if (!input)
  3420. return;
  3421. const _options = {
  3422. ...DEFAULT_OPTIONS,
  3423. ...options,
  3424. ...localOptions
  3425. };
  3426. input.multiple = _options.multiple;
  3427. input.accept = _options.accept;
  3428. input.webkitdirectory = _options.directory;
  3429. if (shared.hasOwn(_options, "capture"))
  3430. input.capture = _options.capture;
  3431. if (_options.reset)
  3432. reset();
  3433. input.click();
  3434. };
  3435. return {
  3436. files: vue.readonly(files),
  3437. open,
  3438. reset,
  3439. onCancel,
  3440. onChange
  3441. };
  3442. }
  3443. function useFileSystemAccess(options = {}) {
  3444. const {
  3445. window: _window = defaultWindow,
  3446. dataType = "Text"
  3447. } = options;
  3448. const window = _window;
  3449. const isSupported = useSupported(() => window && "showSaveFilePicker" in window && "showOpenFilePicker" in window);
  3450. const fileHandle = vue.ref();
  3451. const data = vue.ref();
  3452. const file = vue.ref();
  3453. const fileName = vue.computed(() => {
  3454. var _a, _b;
  3455. return (_b = (_a = file.value) == null ? void 0 : _a.name) != null ? _b : "";
  3456. });
  3457. const fileMIME = vue.computed(() => {
  3458. var _a, _b;
  3459. return (_b = (_a = file.value) == null ? void 0 : _a.type) != null ? _b : "";
  3460. });
  3461. const fileSize = vue.computed(() => {
  3462. var _a, _b;
  3463. return (_b = (_a = file.value) == null ? void 0 : _a.size) != null ? _b : 0;
  3464. });
  3465. const fileLastModified = vue.computed(() => {
  3466. var _a, _b;
  3467. return (_b = (_a = file.value) == null ? void 0 : _a.lastModified) != null ? _b : 0;
  3468. });
  3469. async function open(_options = {}) {
  3470. if (!isSupported.value)
  3471. return;
  3472. const [handle] = await window.showOpenFilePicker({ ...shared.toValue(options), ..._options });
  3473. fileHandle.value = handle;
  3474. await updateData();
  3475. }
  3476. async function create(_options = {}) {
  3477. if (!isSupported.value)
  3478. return;
  3479. fileHandle.value = await window.showSaveFilePicker({ ...options, ..._options });
  3480. data.value = void 0;
  3481. await updateData();
  3482. }
  3483. async function save(_options = {}) {
  3484. if (!isSupported.value)
  3485. return;
  3486. if (!fileHandle.value)
  3487. return saveAs(_options);
  3488. if (data.value) {
  3489. const writableStream = await fileHandle.value.createWritable();
  3490. await writableStream.write(data.value);
  3491. await writableStream.close();
  3492. }
  3493. await updateFile();
  3494. }
  3495. async function saveAs(_options = {}) {
  3496. if (!isSupported.value)
  3497. return;
  3498. fileHandle.value = await window.showSaveFilePicker({ ...options, ..._options });
  3499. if (data.value) {
  3500. const writableStream = await fileHandle.value.createWritable();
  3501. await writableStream.write(data.value);
  3502. await writableStream.close();
  3503. }
  3504. await updateFile();
  3505. }
  3506. async function updateFile() {
  3507. var _a;
  3508. file.value = await ((_a = fileHandle.value) == null ? void 0 : _a.getFile());
  3509. }
  3510. async function updateData() {
  3511. var _a, _b;
  3512. await updateFile();
  3513. const type = shared.toValue(dataType);
  3514. if (type === "Text")
  3515. data.value = await ((_a = file.value) == null ? void 0 : _a.text());
  3516. else if (type === "ArrayBuffer")
  3517. data.value = await ((_b = file.value) == null ? void 0 : _b.arrayBuffer());
  3518. else if (type === "Blob")
  3519. data.value = file.value;
  3520. }
  3521. vue.watch(() => shared.toValue(dataType), updateData);
  3522. return {
  3523. isSupported,
  3524. data,
  3525. file,
  3526. fileName,
  3527. fileMIME,
  3528. fileSize,
  3529. fileLastModified,
  3530. open,
  3531. create,
  3532. save,
  3533. saveAs,
  3534. updateData
  3535. };
  3536. }
  3537. function useFocus(target, options = {}) {
  3538. const { initialValue = false, focusVisible = false, preventScroll = false } = options;
  3539. const innerFocused = vue.ref(false);
  3540. const targetElement = vue.computed(() => unrefElement(target));
  3541. useEventListener(targetElement, "focus", (event) => {
  3542. var _a, _b;
  3543. if (!focusVisible || ((_b = (_a = event.target).matches) == null ? void 0 : _b.call(_a, ":focus-visible")))
  3544. innerFocused.value = true;
  3545. });
  3546. useEventListener(targetElement, "blur", () => innerFocused.value = false);
  3547. const focused = vue.computed({
  3548. get: () => innerFocused.value,
  3549. set(value) {
  3550. var _a, _b;
  3551. if (!value && innerFocused.value)
  3552. (_a = targetElement.value) == null ? void 0 : _a.blur();
  3553. else if (value && !innerFocused.value)
  3554. (_b = targetElement.value) == null ? void 0 : _b.focus({ preventScroll });
  3555. }
  3556. });
  3557. vue.watch(
  3558. targetElement,
  3559. () => {
  3560. focused.value = initialValue;
  3561. },
  3562. { immediate: true, flush: "post" }
  3563. );
  3564. return { focused };
  3565. }
  3566. const EVENT_FOCUS_IN = "focusin";
  3567. const EVENT_FOCUS_OUT = "focusout";
  3568. function useFocusWithin(target, options = {}) {
  3569. const { window = defaultWindow } = options;
  3570. const targetElement = vue.computed(() => unrefElement(target));
  3571. const _focused = vue.ref(false);
  3572. const focused = vue.computed(() => _focused.value);
  3573. const activeElement = useActiveElement(options);
  3574. if (!window || !activeElement.value) {
  3575. return { focused };
  3576. }
  3577. useEventListener(targetElement, EVENT_FOCUS_IN, () => _focused.value = true);
  3578. useEventListener(targetElement, EVENT_FOCUS_OUT, () => _focused.value = false);
  3579. return { focused };
  3580. }
  3581. function useFps(options) {
  3582. var _a;
  3583. const fps = vue.ref(0);
  3584. if (typeof performance === "undefined")
  3585. return fps;
  3586. const every = (_a = options == null ? void 0 : options.every) != null ? _a : 10;
  3587. let last = performance.now();
  3588. let ticks = 0;
  3589. useRafFn(() => {
  3590. ticks += 1;
  3591. if (ticks >= every) {
  3592. const now = performance.now();
  3593. const diff = now - last;
  3594. fps.value = Math.round(1e3 / (diff / ticks));
  3595. last = now;
  3596. ticks = 0;
  3597. }
  3598. });
  3599. return fps;
  3600. }
  3601. const eventHandlers = [
  3602. "fullscreenchange",
  3603. "webkitfullscreenchange",
  3604. "webkitendfullscreen",
  3605. "mozfullscreenchange",
  3606. "MSFullscreenChange"
  3607. ];
  3608. function useFullscreen(target, options = {}) {
  3609. const {
  3610. document = defaultDocument,
  3611. autoExit = false
  3612. } = options;
  3613. const targetRef = vue.computed(() => {
  3614. var _a;
  3615. return (_a = unrefElement(target)) != null ? _a : document == null ? void 0 : document.querySelector("html");
  3616. });
  3617. const isFullscreen = vue.ref(false);
  3618. const requestMethod = vue.computed(() => {
  3619. return [
  3620. "requestFullscreen",
  3621. "webkitRequestFullscreen",
  3622. "webkitEnterFullscreen",
  3623. "webkitEnterFullScreen",
  3624. "webkitRequestFullScreen",
  3625. "mozRequestFullScreen",
  3626. "msRequestFullscreen"
  3627. ].find((m) => document && m in document || targetRef.value && m in targetRef.value);
  3628. });
  3629. const exitMethod = vue.computed(() => {
  3630. return [
  3631. "exitFullscreen",
  3632. "webkitExitFullscreen",
  3633. "webkitExitFullScreen",
  3634. "webkitCancelFullScreen",
  3635. "mozCancelFullScreen",
  3636. "msExitFullscreen"
  3637. ].find((m) => document && m in document || targetRef.value && m in targetRef.value);
  3638. });
  3639. const fullscreenEnabled = vue.computed(() => {
  3640. return [
  3641. "fullScreen",
  3642. "webkitIsFullScreen",
  3643. "webkitDisplayingFullscreen",
  3644. "mozFullScreen",
  3645. "msFullscreenElement"
  3646. ].find((m) => document && m in document || targetRef.value && m in targetRef.value);
  3647. });
  3648. const fullscreenElementMethod = [
  3649. "fullscreenElement",
  3650. "webkitFullscreenElement",
  3651. "mozFullScreenElement",
  3652. "msFullscreenElement"
  3653. ].find((m) => document && m in document);
  3654. const isSupported = useSupported(() => targetRef.value && document && requestMethod.value !== void 0 && exitMethod.value !== void 0 && fullscreenEnabled.value !== void 0);
  3655. const isCurrentElementFullScreen = () => {
  3656. if (fullscreenElementMethod)
  3657. return (document == null ? void 0 : document[fullscreenElementMethod]) === targetRef.value;
  3658. return false;
  3659. };
  3660. const isElementFullScreen = () => {
  3661. if (fullscreenEnabled.value) {
  3662. if (document && document[fullscreenEnabled.value] != null) {
  3663. return document[fullscreenEnabled.value];
  3664. } else {
  3665. const target2 = targetRef.value;
  3666. if ((target2 == null ? void 0 : target2[fullscreenEnabled.value]) != null) {
  3667. return Boolean(target2[fullscreenEnabled.value]);
  3668. }
  3669. }
  3670. }
  3671. return false;
  3672. };
  3673. async function exit() {
  3674. if (!isSupported.value || !isFullscreen.value)
  3675. return;
  3676. if (exitMethod.value) {
  3677. if ((document == null ? void 0 : document[exitMethod.value]) != null) {
  3678. await document[exitMethod.value]();
  3679. } else {
  3680. const target2 = targetRef.value;
  3681. if ((target2 == null ? void 0 : target2[exitMethod.value]) != null)
  3682. await target2[exitMethod.value]();
  3683. }
  3684. }
  3685. isFullscreen.value = false;
  3686. }
  3687. async function enter() {
  3688. if (!isSupported.value || isFullscreen.value)
  3689. return;
  3690. if (isElementFullScreen())
  3691. await exit();
  3692. const target2 = targetRef.value;
  3693. if (requestMethod.value && (target2 == null ? void 0 : target2[requestMethod.value]) != null) {
  3694. await target2[requestMethod.value]();
  3695. isFullscreen.value = true;
  3696. }
  3697. }
  3698. async function toggle() {
  3699. await (isFullscreen.value ? exit() : enter());
  3700. }
  3701. const handlerCallback = () => {
  3702. const isElementFullScreenValue = isElementFullScreen();
  3703. if (!isElementFullScreenValue || isElementFullScreenValue && isCurrentElementFullScreen())
  3704. isFullscreen.value = isElementFullScreenValue;
  3705. };
  3706. useEventListener(document, eventHandlers, handlerCallback, false);
  3707. useEventListener(() => unrefElement(targetRef), eventHandlers, handlerCallback, false);
  3708. if (autoExit)
  3709. shared.tryOnScopeDispose(exit);
  3710. return {
  3711. isSupported,
  3712. isFullscreen,
  3713. enter,
  3714. exit,
  3715. toggle
  3716. };
  3717. }
  3718. function mapGamepadToXbox360Controller(gamepad) {
  3719. return vue.computed(() => {
  3720. if (gamepad.value) {
  3721. return {
  3722. buttons: {
  3723. a: gamepad.value.buttons[0],
  3724. b: gamepad.value.buttons[1],
  3725. x: gamepad.value.buttons[2],
  3726. y: gamepad.value.buttons[3]
  3727. },
  3728. bumper: {
  3729. left: gamepad.value.buttons[4],
  3730. right: gamepad.value.buttons[5]
  3731. },
  3732. triggers: {
  3733. left: gamepad.value.buttons[6],
  3734. right: gamepad.value.buttons[7]
  3735. },
  3736. stick: {
  3737. left: {
  3738. horizontal: gamepad.value.axes[0],
  3739. vertical: gamepad.value.axes[1],
  3740. button: gamepad.value.buttons[10]
  3741. },
  3742. right: {
  3743. horizontal: gamepad.value.axes[2],
  3744. vertical: gamepad.value.axes[3],
  3745. button: gamepad.value.buttons[11]
  3746. }
  3747. },
  3748. dpad: {
  3749. up: gamepad.value.buttons[12],
  3750. down: gamepad.value.buttons[13],
  3751. left: gamepad.value.buttons[14],
  3752. right: gamepad.value.buttons[15]
  3753. },
  3754. back: gamepad.value.buttons[8],
  3755. start: gamepad.value.buttons[9]
  3756. };
  3757. }
  3758. return null;
  3759. });
  3760. }
  3761. function useGamepad(options = {}) {
  3762. const {
  3763. navigator = defaultNavigator
  3764. } = options;
  3765. const isSupported = useSupported(() => navigator && "getGamepads" in navigator);
  3766. const gamepads = vue.ref([]);
  3767. const onConnectedHook = shared.createEventHook();
  3768. const onDisconnectedHook = shared.createEventHook();
  3769. const stateFromGamepad = (gamepad) => {
  3770. const hapticActuators = [];
  3771. const vibrationActuator = "vibrationActuator" in gamepad ? gamepad.vibrationActuator : null;
  3772. if (vibrationActuator)
  3773. hapticActuators.push(vibrationActuator);
  3774. if (gamepad.hapticActuators)
  3775. hapticActuators.push(...gamepad.hapticActuators);
  3776. return {
  3777. id: gamepad.id,
  3778. index: gamepad.index,
  3779. connected: gamepad.connected,
  3780. mapping: gamepad.mapping,
  3781. timestamp: gamepad.timestamp,
  3782. vibrationActuator: gamepad.vibrationActuator,
  3783. hapticActuators,
  3784. axes: gamepad.axes.map((axes) => axes),
  3785. buttons: gamepad.buttons.map((button) => ({ pressed: button.pressed, touched: button.touched, value: button.value }))
  3786. };
  3787. };
  3788. const updateGamepadState = () => {
  3789. const _gamepads = (navigator == null ? void 0 : navigator.getGamepads()) || [];
  3790. for (const gamepad of _gamepads) {
  3791. if (gamepad && gamepads.value[gamepad.index])
  3792. gamepads.value[gamepad.index] = stateFromGamepad(gamepad);
  3793. }
  3794. };
  3795. const { isActive, pause, resume } = useRafFn(updateGamepadState);
  3796. const onGamepadConnected = (gamepad) => {
  3797. if (!gamepads.value.some(({ index }) => index === gamepad.index)) {
  3798. gamepads.value.push(stateFromGamepad(gamepad));
  3799. onConnectedHook.trigger(gamepad.index);
  3800. }
  3801. resume();
  3802. };
  3803. const onGamepadDisconnected = (gamepad) => {
  3804. gamepads.value = gamepads.value.filter((x) => x.index !== gamepad.index);
  3805. onDisconnectedHook.trigger(gamepad.index);
  3806. };
  3807. useEventListener("gamepadconnected", (e) => onGamepadConnected(e.gamepad));
  3808. useEventListener("gamepaddisconnected", (e) => onGamepadDisconnected(e.gamepad));
  3809. shared.tryOnMounted(() => {
  3810. const _gamepads = (navigator == null ? void 0 : navigator.getGamepads()) || [];
  3811. for (const gamepad of _gamepads) {
  3812. if (gamepad && gamepads.value[gamepad.index])
  3813. onGamepadConnected(gamepad);
  3814. }
  3815. });
  3816. pause();
  3817. return {
  3818. isSupported,
  3819. onConnected: onConnectedHook.on,
  3820. onDisconnected: onDisconnectedHook.on,
  3821. gamepads,
  3822. pause,
  3823. resume,
  3824. isActive
  3825. };
  3826. }
  3827. function useGeolocation(options = {}) {
  3828. const {
  3829. enableHighAccuracy = true,
  3830. maximumAge = 3e4,
  3831. timeout = 27e3,
  3832. navigator = defaultNavigator,
  3833. immediate = true
  3834. } = options;
  3835. const isSupported = useSupported(() => navigator && "geolocation" in navigator);
  3836. const locatedAt = vue.ref(null);
  3837. const error = vue.shallowRef(null);
  3838. const coords = vue.ref({
  3839. accuracy: 0,
  3840. latitude: Number.POSITIVE_INFINITY,
  3841. longitude: Number.POSITIVE_INFINITY,
  3842. altitude: null,
  3843. altitudeAccuracy: null,
  3844. heading: null,
  3845. speed: null
  3846. });
  3847. function updatePosition(position) {
  3848. locatedAt.value = position.timestamp;
  3849. coords.value = position.coords;
  3850. error.value = null;
  3851. }
  3852. let watcher;
  3853. function resume() {
  3854. if (isSupported.value) {
  3855. watcher = navigator.geolocation.watchPosition(
  3856. updatePosition,
  3857. (err) => error.value = err,
  3858. {
  3859. enableHighAccuracy,
  3860. maximumAge,
  3861. timeout
  3862. }
  3863. );
  3864. }
  3865. }
  3866. if (immediate)
  3867. resume();
  3868. function pause() {
  3869. if (watcher && navigator)
  3870. navigator.geolocation.clearWatch(watcher);
  3871. }
  3872. shared.tryOnScopeDispose(() => {
  3873. pause();
  3874. });
  3875. return {
  3876. isSupported,
  3877. coords,
  3878. locatedAt,
  3879. error,
  3880. resume,
  3881. pause
  3882. };
  3883. }
  3884. const defaultEvents$1 = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"];
  3885. const oneMinute = 6e4;
  3886. function useIdle(timeout = oneMinute, options = {}) {
  3887. const {
  3888. initialState = false,
  3889. listenForVisibilityChange = true,
  3890. events = defaultEvents$1,
  3891. window = defaultWindow,
  3892. eventFilter = shared.throttleFilter(50)
  3893. } = options;
  3894. const idle = vue.ref(initialState);
  3895. const lastActive = vue.ref(shared.timestamp());
  3896. let timer;
  3897. const reset = () => {
  3898. idle.value = false;
  3899. clearTimeout(timer);
  3900. timer = setTimeout(() => idle.value = true, timeout);
  3901. };
  3902. const onEvent = shared.createFilterWrapper(
  3903. eventFilter,
  3904. () => {
  3905. lastActive.value = shared.timestamp();
  3906. reset();
  3907. }
  3908. );
  3909. if (window) {
  3910. const document = window.document;
  3911. for (const event of events)
  3912. useEventListener(window, event, onEvent, { passive: true });
  3913. if (listenForVisibilityChange) {
  3914. useEventListener(document, "visibilitychange", () => {
  3915. if (!document.hidden)
  3916. onEvent();
  3917. });
  3918. }
  3919. reset();
  3920. }
  3921. return {
  3922. idle,
  3923. lastActive,
  3924. reset
  3925. };
  3926. }
  3927. async function loadImage(options) {
  3928. return new Promise((resolve, reject) => {
  3929. const img = new Image();
  3930. const { src, srcset, sizes, class: clazz, loading, crossorigin, referrerPolicy } = options;
  3931. img.src = src;
  3932. if (srcset)
  3933. img.srcset = srcset;
  3934. if (sizes)
  3935. img.sizes = sizes;
  3936. if (clazz)
  3937. img.className = clazz;
  3938. if (loading)
  3939. img.loading = loading;
  3940. if (crossorigin)
  3941. img.crossOrigin = crossorigin;
  3942. if (referrerPolicy)
  3943. img.referrerPolicy = referrerPolicy;
  3944. img.onload = () => resolve(img);
  3945. img.onerror = reject;
  3946. });
  3947. }
  3948. function useImage(options, asyncStateOptions = {}) {
  3949. const state = useAsyncState(
  3950. () => loadImage(shared.toValue(options)),
  3951. void 0,
  3952. {
  3953. resetOnExecute: true,
  3954. ...asyncStateOptions
  3955. }
  3956. );
  3957. vue.watch(
  3958. () => shared.toValue(options),
  3959. () => state.execute(asyncStateOptions.delay),
  3960. { deep: true }
  3961. );
  3962. return state;
  3963. }
  3964. function resolveElement(el) {
  3965. if (typeof Window !== "undefined" && el instanceof Window)
  3966. return el.document.documentElement;
  3967. if (typeof Document !== "undefined" && el instanceof Document)
  3968. return el.documentElement;
  3969. return el;
  3970. }
  3971. const ARRIVED_STATE_THRESHOLD_PIXELS = 1;
  3972. function useScroll(element, options = {}) {
  3973. const {
  3974. throttle = 0,
  3975. idle = 200,
  3976. onStop = shared.noop,
  3977. onScroll = shared.noop,
  3978. offset = {
  3979. left: 0,
  3980. right: 0,
  3981. top: 0,
  3982. bottom: 0
  3983. },
  3984. eventListenerOptions = {
  3985. capture: false,
  3986. passive: true
  3987. },
  3988. behavior = "auto",
  3989. window = defaultWindow,
  3990. onError = (e) => {
  3991. console.error(e);
  3992. }
  3993. } = options;
  3994. const internalX = vue.ref(0);
  3995. const internalY = vue.ref(0);
  3996. const x = vue.computed({
  3997. get() {
  3998. return internalX.value;
  3999. },
  4000. set(x2) {
  4001. scrollTo(x2, void 0);
  4002. }
  4003. });
  4004. const y = vue.computed({
  4005. get() {
  4006. return internalY.value;
  4007. },
  4008. set(y2) {
  4009. scrollTo(void 0, y2);
  4010. }
  4011. });
  4012. function scrollTo(_x, _y) {
  4013. var _a, _b, _c, _d;
  4014. if (!window)
  4015. return;
  4016. const _element = shared.toValue(element);
  4017. if (!_element)
  4018. return;
  4019. (_c = _element instanceof Document ? window.document.body : _element) == null ? void 0 : _c.scrollTo({
  4020. top: (_a = shared.toValue(_y)) != null ? _a : y.value,
  4021. left: (_b = shared.toValue(_x)) != null ? _b : x.value,
  4022. behavior: shared.toValue(behavior)
  4023. });
  4024. const scrollContainer = ((_d = _element == null ? void 0 : _element.document) == null ? void 0 : _d.documentElement) || (_element == null ? void 0 : _element.documentElement) || _element;
  4025. if (x != null)
  4026. internalX.value = scrollContainer.scrollLeft;
  4027. if (y != null)
  4028. internalY.value = scrollContainer.scrollTop;
  4029. }
  4030. const isScrolling = vue.ref(false);
  4031. const arrivedState = vue.reactive({
  4032. left: true,
  4033. right: false,
  4034. top: true,
  4035. bottom: false
  4036. });
  4037. const directions = vue.reactive({
  4038. left: false,
  4039. right: false,
  4040. top: false,
  4041. bottom: false
  4042. });
  4043. const onScrollEnd = (e) => {
  4044. if (!isScrolling.value)
  4045. return;
  4046. isScrolling.value = false;
  4047. directions.left = false;
  4048. directions.right = false;
  4049. directions.top = false;
  4050. directions.bottom = false;
  4051. onStop(e);
  4052. };
  4053. const onScrollEndDebounced = shared.useDebounceFn(onScrollEnd, throttle + idle);
  4054. const setArrivedState = (target) => {
  4055. var _a;
  4056. if (!window)
  4057. return;
  4058. const el = ((_a = target == null ? void 0 : target.document) == null ? void 0 : _a.documentElement) || (target == null ? void 0 : target.documentElement) || unrefElement(target);
  4059. const { display, flexDirection } = getComputedStyle(el);
  4060. const scrollLeft = el.scrollLeft;
  4061. directions.left = scrollLeft < internalX.value;
  4062. directions.right = scrollLeft > internalX.value;
  4063. const left = Math.abs(scrollLeft) <= (offset.left || 0);
  4064. const right = Math.abs(scrollLeft) + el.clientWidth >= el.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
  4065. if (display === "flex" && flexDirection === "row-reverse") {
  4066. arrivedState.left = right;
  4067. arrivedState.right = left;
  4068. } else {
  4069. arrivedState.left = left;
  4070. arrivedState.right = right;
  4071. }
  4072. internalX.value = scrollLeft;
  4073. let scrollTop = el.scrollTop;
  4074. if (target === window.document && !scrollTop)
  4075. scrollTop = window.document.body.scrollTop;
  4076. directions.top = scrollTop < internalY.value;
  4077. directions.bottom = scrollTop > internalY.value;
  4078. const top = Math.abs(scrollTop) <= (offset.top || 0);
  4079. const bottom = Math.abs(scrollTop) + el.clientHeight >= el.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
  4080. if (display === "flex" && flexDirection === "column-reverse") {
  4081. arrivedState.top = bottom;
  4082. arrivedState.bottom = top;
  4083. } else {
  4084. arrivedState.top = top;
  4085. arrivedState.bottom = bottom;
  4086. }
  4087. internalY.value = scrollTop;
  4088. };
  4089. const onScrollHandler = (e) => {
  4090. var _a;
  4091. if (!window)
  4092. return;
  4093. const eventTarget = (_a = e.target.documentElement) != null ? _a : e.target;
  4094. setArrivedState(eventTarget);
  4095. isScrolling.value = true;
  4096. onScrollEndDebounced(e);
  4097. onScroll(e);
  4098. };
  4099. useEventListener(
  4100. element,
  4101. "scroll",
  4102. throttle ? shared.useThrottleFn(onScrollHandler, throttle, true, false) : onScrollHandler,
  4103. eventListenerOptions
  4104. );
  4105. shared.tryOnMounted(() => {
  4106. try {
  4107. const _element = shared.toValue(element);
  4108. if (!_element)
  4109. return;
  4110. setArrivedState(_element);
  4111. } catch (e) {
  4112. onError(e);
  4113. }
  4114. });
  4115. useEventListener(
  4116. element,
  4117. "scrollend",
  4118. onScrollEnd,
  4119. eventListenerOptions
  4120. );
  4121. return {
  4122. x,
  4123. y,
  4124. isScrolling,
  4125. arrivedState,
  4126. directions,
  4127. measure() {
  4128. const _element = shared.toValue(element);
  4129. if (window && _element)
  4130. setArrivedState(_element);
  4131. }
  4132. };
  4133. }
  4134. function useInfiniteScroll(element, onLoadMore, options = {}) {
  4135. var _a;
  4136. const {
  4137. direction = "bottom",
  4138. interval = 100,
  4139. canLoadMore = () => true
  4140. } = options;
  4141. const state = vue.reactive(useScroll(
  4142. element,
  4143. {
  4144. ...options,
  4145. offset: {
  4146. [direction]: (_a = options.distance) != null ? _a : 0,
  4147. ...options.offset
  4148. }
  4149. }
  4150. ));
  4151. const promise = vue.ref();
  4152. const isLoading = vue.computed(() => !!promise.value);
  4153. const observedElement = vue.computed(() => {
  4154. return resolveElement(shared.toValue(element));
  4155. });
  4156. const isElementVisible = useElementVisibility(observedElement);
  4157. function checkAndLoad() {
  4158. state.measure();
  4159. if (!observedElement.value || !isElementVisible.value || !canLoadMore(observedElement.value))
  4160. return;
  4161. const { scrollHeight, clientHeight, scrollWidth, clientWidth } = observedElement.value;
  4162. const isNarrower = direction === "bottom" || direction === "top" ? scrollHeight <= clientHeight : scrollWidth <= clientWidth;
  4163. if (state.arrivedState[direction] || isNarrower) {
  4164. if (!promise.value) {
  4165. promise.value = Promise.all([
  4166. onLoadMore(state),
  4167. new Promise((resolve) => setTimeout(resolve, interval))
  4168. ]).finally(() => {
  4169. promise.value = null;
  4170. vue.nextTick(() => checkAndLoad());
  4171. });
  4172. }
  4173. }
  4174. }
  4175. const stop = vue.watch(
  4176. () => [state.arrivedState[direction], isElementVisible.value],
  4177. checkAndLoad,
  4178. { immediate: true }
  4179. );
  4180. shared.tryOnUnmounted(stop);
  4181. return {
  4182. isLoading,
  4183. reset() {
  4184. vue.nextTick(() => checkAndLoad());
  4185. }
  4186. };
  4187. }
  4188. const defaultEvents = ["mousedown", "mouseup", "keydown", "keyup"];
  4189. function useKeyModifier(modifier, options = {}) {
  4190. const {
  4191. events = defaultEvents,
  4192. document = defaultDocument,
  4193. initial = null
  4194. } = options;
  4195. const state = vue.ref(initial);
  4196. if (document) {
  4197. events.forEach((listenerEvent) => {
  4198. useEventListener(document, listenerEvent, (evt) => {
  4199. if (typeof evt.getModifierState === "function")
  4200. state.value = evt.getModifierState(modifier);
  4201. });
  4202. });
  4203. }
  4204. return state;
  4205. }
  4206. function useLocalStorage(key, initialValue, options = {}) {
  4207. const { window = defaultWindow } = options;
  4208. return useStorage(key, initialValue, window == null ? void 0 : window.localStorage, options);
  4209. }
  4210. const DefaultMagicKeysAliasMap = {
  4211. ctrl: "control",
  4212. command: "meta",
  4213. cmd: "meta",
  4214. option: "alt",
  4215. up: "arrowup",
  4216. down: "arrowdown",
  4217. left: "arrowleft",
  4218. right: "arrowright"
  4219. };
  4220. function useMagicKeys(options = {}) {
  4221. const {
  4222. reactive: useReactive = false,
  4223. target = defaultWindow,
  4224. aliasMap = DefaultMagicKeysAliasMap,
  4225. passive = true,
  4226. onEventFired = shared.noop
  4227. } = options;
  4228. const current = vue.reactive(/* @__PURE__ */ new Set());
  4229. const obj = {
  4230. toJSON() {
  4231. return {};
  4232. },
  4233. current
  4234. };
  4235. const refs = useReactive ? vue.reactive(obj) : obj;
  4236. const metaDeps = /* @__PURE__ */ new Set();
  4237. const usedKeys = /* @__PURE__ */ new Set();
  4238. function setRefs(key, value) {
  4239. if (key in refs) {
  4240. if (useReactive)
  4241. refs[key] = value;
  4242. else
  4243. refs[key].value = value;
  4244. }
  4245. }
  4246. function reset() {
  4247. current.clear();
  4248. for (const key of usedKeys)
  4249. setRefs(key, false);
  4250. }
  4251. function updateRefs(e, value) {
  4252. var _a, _b;
  4253. const key = (_a = e.key) == null ? void 0 : _a.toLowerCase();
  4254. const code = (_b = e.code) == null ? void 0 : _b.toLowerCase();
  4255. const values = [code, key].filter(Boolean);
  4256. if (key) {
  4257. if (value)
  4258. current.add(key);
  4259. else
  4260. current.delete(key);
  4261. }
  4262. for (const key2 of values) {
  4263. usedKeys.add(key2);
  4264. setRefs(key2, value);
  4265. }
  4266. if (key === "meta" && !value) {
  4267. metaDeps.forEach((key2) => {
  4268. current.delete(key2);
  4269. setRefs(key2, false);
  4270. });
  4271. metaDeps.clear();
  4272. } else if (typeof e.getModifierState === "function" && e.getModifierState("Meta") && value) {
  4273. [...current, ...values].forEach((key2) => metaDeps.add(key2));
  4274. }
  4275. }
  4276. useEventListener(target, "keydown", (e) => {
  4277. updateRefs(e, true);
  4278. return onEventFired(e);
  4279. }, { passive });
  4280. useEventListener(target, "keyup", (e) => {
  4281. updateRefs(e, false);
  4282. return onEventFired(e);
  4283. }, { passive });
  4284. useEventListener("blur", reset, { passive: true });
  4285. useEventListener("focus", reset, { passive: true });
  4286. const proxy = new Proxy(
  4287. refs,
  4288. {
  4289. get(target2, prop, rec) {
  4290. if (typeof prop !== "string")
  4291. return Reflect.get(target2, prop, rec);
  4292. prop = prop.toLowerCase();
  4293. if (prop in aliasMap)
  4294. prop = aliasMap[prop];
  4295. if (!(prop in refs)) {
  4296. if (/[+_-]/.test(prop)) {
  4297. const keys = prop.split(/[+_-]/g).map((i) => i.trim());
  4298. refs[prop] = vue.computed(() => keys.every((key) => shared.toValue(proxy[key])));
  4299. } else {
  4300. refs[prop] = vue.ref(false);
  4301. }
  4302. }
  4303. const r = Reflect.get(target2, prop, rec);
  4304. return useReactive ? shared.toValue(r) : r;
  4305. }
  4306. }
  4307. );
  4308. return proxy;
  4309. }
  4310. function usingElRef(source, cb) {
  4311. if (shared.toValue(source))
  4312. cb(shared.toValue(source));
  4313. }
  4314. function timeRangeToArray(timeRanges) {
  4315. let ranges = [];
  4316. for (let i = 0; i < timeRanges.length; ++i)
  4317. ranges = [...ranges, [timeRanges.start(i), timeRanges.end(i)]];
  4318. return ranges;
  4319. }
  4320. function tracksToArray(tracks) {
  4321. return Array.from(tracks).map(({ label, kind, language, mode, activeCues, cues, inBandMetadataTrackDispatchType }, id) => ({ id, label, kind, language, mode, activeCues, cues, inBandMetadataTrackDispatchType }));
  4322. }
  4323. const defaultOptions = {
  4324. src: "",
  4325. tracks: []
  4326. };
  4327. function useMediaControls(target, options = {}) {
  4328. target = shared.toRef(target);
  4329. options = {
  4330. ...defaultOptions,
  4331. ...options
  4332. };
  4333. const {
  4334. document = defaultDocument
  4335. } = options;
  4336. const currentTime = vue.ref(0);
  4337. const duration = vue.ref(0);
  4338. const seeking = vue.ref(false);
  4339. const volume = vue.ref(1);
  4340. const waiting = vue.ref(false);
  4341. const ended = vue.ref(false);
  4342. const playing = vue.ref(false);
  4343. const rate = vue.ref(1);
  4344. const stalled = vue.ref(false);
  4345. const buffered = vue.ref([]);
  4346. const tracks = vue.ref([]);
  4347. const selectedTrack = vue.ref(-1);
  4348. const isPictureInPicture = vue.ref(false);
  4349. const muted = vue.ref(false);
  4350. const supportsPictureInPicture = document && "pictureInPictureEnabled" in document;
  4351. const sourceErrorEvent = shared.createEventHook();
  4352. const playbackErrorEvent = shared.createEventHook();
  4353. const disableTrack = (track) => {
  4354. usingElRef(target, (el) => {
  4355. if (track) {
  4356. const id = typeof track === "number" ? track : track.id;
  4357. el.textTracks[id].mode = "disabled";
  4358. } else {
  4359. for (let i = 0; i < el.textTracks.length; ++i)
  4360. el.textTracks[i].mode = "disabled";
  4361. }
  4362. selectedTrack.value = -1;
  4363. });
  4364. };
  4365. const enableTrack = (track, disableTracks = true) => {
  4366. usingElRef(target, (el) => {
  4367. const id = typeof track === "number" ? track : track.id;
  4368. if (disableTracks)
  4369. disableTrack();
  4370. el.textTracks[id].mode = "showing";
  4371. selectedTrack.value = id;
  4372. });
  4373. };
  4374. const togglePictureInPicture = () => {
  4375. return new Promise((resolve, reject) => {
  4376. usingElRef(target, async (el) => {
  4377. if (supportsPictureInPicture) {
  4378. if (!isPictureInPicture.value) {
  4379. el.requestPictureInPicture().then(resolve).catch(reject);
  4380. } else {
  4381. document.exitPictureInPicture().then(resolve).catch(reject);
  4382. }
  4383. }
  4384. });
  4385. });
  4386. };
  4387. vue.watchEffect(() => {
  4388. if (!document)
  4389. return;
  4390. const el = shared.toValue(target);
  4391. if (!el)
  4392. return;
  4393. const src = shared.toValue(options.src);
  4394. let sources = [];
  4395. if (!src)
  4396. return;
  4397. if (typeof src === "string")
  4398. sources = [{ src }];
  4399. else if (Array.isArray(src))
  4400. sources = src;
  4401. else if (shared.isObject(src))
  4402. sources = [src];
  4403. el.querySelectorAll("source").forEach((e) => {
  4404. e.removeEventListener("error", sourceErrorEvent.trigger);
  4405. e.remove();
  4406. });
  4407. sources.forEach(({ src: src2, type }) => {
  4408. const source = document.createElement("source");
  4409. source.setAttribute("src", src2);
  4410. source.setAttribute("type", type || "");
  4411. source.addEventListener("error", sourceErrorEvent.trigger);
  4412. el.appendChild(source);
  4413. });
  4414. el.load();
  4415. });
  4416. shared.tryOnScopeDispose(() => {
  4417. const el = shared.toValue(target);
  4418. if (!el)
  4419. return;
  4420. el.querySelectorAll("source").forEach((e) => e.removeEventListener("error", sourceErrorEvent.trigger));
  4421. });
  4422. vue.watch([target, volume], () => {
  4423. const el = shared.toValue(target);
  4424. if (!el)
  4425. return;
  4426. el.volume = volume.value;
  4427. });
  4428. vue.watch([target, muted], () => {
  4429. const el = shared.toValue(target);
  4430. if (!el)
  4431. return;
  4432. el.muted = muted.value;
  4433. });
  4434. vue.watch([target, rate], () => {
  4435. const el = shared.toValue(target);
  4436. if (!el)
  4437. return;
  4438. el.playbackRate = rate.value;
  4439. });
  4440. vue.watchEffect(() => {
  4441. if (!document)
  4442. return;
  4443. const textTracks = shared.toValue(options.tracks);
  4444. const el = shared.toValue(target);
  4445. if (!textTracks || !textTracks.length || !el)
  4446. return;
  4447. el.querySelectorAll("track").forEach((e) => e.remove());
  4448. textTracks.forEach(({ default: isDefault, kind, label, src, srcLang }, i) => {
  4449. const track = document.createElement("track");
  4450. track.default = isDefault || false;
  4451. track.kind = kind;
  4452. track.label = label;
  4453. track.src = src;
  4454. track.srclang = srcLang;
  4455. if (track.default)
  4456. selectedTrack.value = i;
  4457. el.appendChild(track);
  4458. });
  4459. });
  4460. const { ignoreUpdates: ignoreCurrentTimeUpdates } = shared.watchIgnorable(currentTime, (time) => {
  4461. const el = shared.toValue(target);
  4462. if (!el)
  4463. return;
  4464. el.currentTime = time;
  4465. });
  4466. const { ignoreUpdates: ignorePlayingUpdates } = shared.watchIgnorable(playing, (isPlaying) => {
  4467. const el = shared.toValue(target);
  4468. if (!el)
  4469. return;
  4470. if (isPlaying) {
  4471. el.play().catch((e) => {
  4472. playbackErrorEvent.trigger(e);
  4473. throw e;
  4474. });
  4475. } else {
  4476. el.pause();
  4477. }
  4478. });
  4479. useEventListener(target, "timeupdate", () => ignoreCurrentTimeUpdates(() => currentTime.value = shared.toValue(target).currentTime));
  4480. useEventListener(target, "durationchange", () => duration.value = shared.toValue(target).duration);
  4481. useEventListener(target, "progress", () => buffered.value = timeRangeToArray(shared.toValue(target).buffered));
  4482. useEventListener(target, "seeking", () => seeking.value = true);
  4483. useEventListener(target, "seeked", () => seeking.value = false);
  4484. useEventListener(target, ["waiting", "loadstart"], () => {
  4485. waiting.value = true;
  4486. ignorePlayingUpdates(() => playing.value = false);
  4487. });
  4488. useEventListener(target, "loadeddata", () => waiting.value = false);
  4489. useEventListener(target, "playing", () => {
  4490. waiting.value = false;
  4491. ended.value = false;
  4492. ignorePlayingUpdates(() => playing.value = true);
  4493. });
  4494. useEventListener(target, "ratechange", () => rate.value = shared.toValue(target).playbackRate);
  4495. useEventListener(target, "stalled", () => stalled.value = true);
  4496. useEventListener(target, "ended", () => ended.value = true);
  4497. useEventListener(target, "pause", () => ignorePlayingUpdates(() => playing.value = false));
  4498. useEventListener(target, "play", () => ignorePlayingUpdates(() => playing.value = true));
  4499. useEventListener(target, "enterpictureinpicture", () => isPictureInPicture.value = true);
  4500. useEventListener(target, "leavepictureinpicture", () => isPictureInPicture.value = false);
  4501. useEventListener(target, "volumechange", () => {
  4502. const el = shared.toValue(target);
  4503. if (!el)
  4504. return;
  4505. volume.value = el.volume;
  4506. muted.value = el.muted;
  4507. });
  4508. const listeners = [];
  4509. const stop = vue.watch([target], () => {
  4510. const el = shared.toValue(target);
  4511. if (!el)
  4512. return;
  4513. stop();
  4514. listeners[0] = useEventListener(el.textTracks, "addtrack", () => tracks.value = tracksToArray(el.textTracks));
  4515. listeners[1] = useEventListener(el.textTracks, "removetrack", () => tracks.value = tracksToArray(el.textTracks));
  4516. listeners[2] = useEventListener(el.textTracks, "change", () => tracks.value = tracksToArray(el.textTracks));
  4517. });
  4518. shared.tryOnScopeDispose(() => listeners.forEach((listener) => listener()));
  4519. return {
  4520. currentTime,
  4521. duration,
  4522. waiting,
  4523. seeking,
  4524. ended,
  4525. stalled,
  4526. buffered,
  4527. playing,
  4528. rate,
  4529. // Volume
  4530. volume,
  4531. muted,
  4532. // Tracks
  4533. tracks,
  4534. selectedTrack,
  4535. enableTrack,
  4536. disableTrack,
  4537. // Picture in Picture
  4538. supportsPictureInPicture,
  4539. togglePictureInPicture,
  4540. isPictureInPicture,
  4541. // Events
  4542. onSourceError: sourceErrorEvent.on,
  4543. onPlaybackError: playbackErrorEvent.on
  4544. };
  4545. }
  4546. function useMemoize(resolver, options) {
  4547. const initCache = () => {
  4548. if (options == null ? void 0 : options.cache)
  4549. return vue.shallowReactive(options.cache);
  4550. return vue.shallowReactive(/* @__PURE__ */ new Map());
  4551. };
  4552. const cache = initCache();
  4553. const generateKey = (...args) => (options == null ? void 0 : options.getKey) ? options.getKey(...args) : JSON.stringify(args);
  4554. const _loadData = (key, ...args) => {
  4555. cache.set(key, resolver(...args));
  4556. return cache.get(key);
  4557. };
  4558. const loadData = (...args) => _loadData(generateKey(...args), ...args);
  4559. const deleteData = (...args) => {
  4560. cache.delete(generateKey(...args));
  4561. };
  4562. const clearData = () => {
  4563. cache.clear();
  4564. };
  4565. const memoized = (...args) => {
  4566. const key = generateKey(...args);
  4567. if (cache.has(key))
  4568. return cache.get(key);
  4569. return _loadData(key, ...args);
  4570. };
  4571. memoized.load = loadData;
  4572. memoized.delete = deleteData;
  4573. memoized.clear = clearData;
  4574. memoized.generateKey = generateKey;
  4575. memoized.cache = cache;
  4576. return memoized;
  4577. }
  4578. function useMemory(options = {}) {
  4579. const memory = vue.ref();
  4580. const isSupported = useSupported(() => typeof performance !== "undefined" && "memory" in performance);
  4581. if (isSupported.value) {
  4582. const { interval = 1e3 } = options;
  4583. shared.useIntervalFn(() => {
  4584. memory.value = performance.memory;
  4585. }, interval, { immediate: options.immediate, immediateCallback: options.immediateCallback });
  4586. }
  4587. return { isSupported, memory };
  4588. }
  4589. const UseMouseBuiltinExtractors = {
  4590. page: (event) => [event.pageX, event.pageY],
  4591. client: (event) => [event.clientX, event.clientY],
  4592. screen: (event) => [event.screenX, event.screenY],
  4593. movement: (event) => event instanceof Touch ? null : [event.movementX, event.movementY]
  4594. };
  4595. function useMouse(options = {}) {
  4596. const {
  4597. type = "page",
  4598. touch = true,
  4599. resetOnTouchEnds = false,
  4600. initialValue = { x: 0, y: 0 },
  4601. window = defaultWindow,
  4602. target = window,
  4603. scroll = true,
  4604. eventFilter
  4605. } = options;
  4606. let _prevMouseEvent = null;
  4607. let _prevScrollX = 0;
  4608. let _prevScrollY = 0;
  4609. const x = vue.ref(initialValue.x);
  4610. const y = vue.ref(initialValue.y);
  4611. const sourceType = vue.ref(null);
  4612. const extractor = typeof type === "function" ? type : UseMouseBuiltinExtractors[type];
  4613. const mouseHandler = (event) => {
  4614. const result = extractor(event);
  4615. _prevMouseEvent = event;
  4616. if (result) {
  4617. [x.value, y.value] = result;
  4618. sourceType.value = "mouse";
  4619. }
  4620. if (window) {
  4621. _prevScrollX = window.scrollX;
  4622. _prevScrollY = window.scrollY;
  4623. }
  4624. };
  4625. const touchHandler = (event) => {
  4626. if (event.touches.length > 0) {
  4627. const result = extractor(event.touches[0]);
  4628. if (result) {
  4629. [x.value, y.value] = result;
  4630. sourceType.value = "touch";
  4631. }
  4632. }
  4633. };
  4634. const scrollHandler = () => {
  4635. if (!_prevMouseEvent || !window)
  4636. return;
  4637. const pos = extractor(_prevMouseEvent);
  4638. if (_prevMouseEvent instanceof MouseEvent && pos) {
  4639. x.value = pos[0] + window.scrollX - _prevScrollX;
  4640. y.value = pos[1] + window.scrollY - _prevScrollY;
  4641. }
  4642. };
  4643. const reset = () => {
  4644. x.value = initialValue.x;
  4645. y.value = initialValue.y;
  4646. };
  4647. const mouseHandlerWrapper = eventFilter ? (event) => eventFilter(() => mouseHandler(event), {}) : (event) => mouseHandler(event);
  4648. const touchHandlerWrapper = eventFilter ? (event) => eventFilter(() => touchHandler(event), {}) : (event) => touchHandler(event);
  4649. const scrollHandlerWrapper = eventFilter ? () => eventFilter(() => scrollHandler(), {}) : () => scrollHandler();
  4650. if (target) {
  4651. const listenerOptions = { passive: true };
  4652. useEventListener(target, ["mousemove", "dragover"], mouseHandlerWrapper, listenerOptions);
  4653. if (touch && type !== "movement") {
  4654. useEventListener(target, ["touchstart", "touchmove"], touchHandlerWrapper, listenerOptions);
  4655. if (resetOnTouchEnds)
  4656. useEventListener(target, "touchend", reset, listenerOptions);
  4657. }
  4658. if (scroll && type === "page")
  4659. useEventListener(window, "scroll", scrollHandlerWrapper, { passive: true });
  4660. }
  4661. return {
  4662. x,
  4663. y,
  4664. sourceType
  4665. };
  4666. }
  4667. function useMouseInElement(target, options = {}) {
  4668. const {
  4669. handleOutside = true,
  4670. window = defaultWindow
  4671. } = options;
  4672. const type = options.type || "page";
  4673. const { x, y, sourceType } = useMouse(options);
  4674. const targetRef = vue.ref(target != null ? target : window == null ? void 0 : window.document.body);
  4675. const elementX = vue.ref(0);
  4676. const elementY = vue.ref(0);
  4677. const elementPositionX = vue.ref(0);
  4678. const elementPositionY = vue.ref(0);
  4679. const elementHeight = vue.ref(0);
  4680. const elementWidth = vue.ref(0);
  4681. const isOutside = vue.ref(true);
  4682. let stop = () => {
  4683. };
  4684. if (window) {
  4685. stop = vue.watch(
  4686. [targetRef, x, y],
  4687. () => {
  4688. const el = unrefElement(targetRef);
  4689. if (!el || !(el instanceof Element))
  4690. return;
  4691. const {
  4692. left,
  4693. top,
  4694. width,
  4695. height
  4696. } = el.getBoundingClientRect();
  4697. elementPositionX.value = left + (type === "page" ? window.pageXOffset : 0);
  4698. elementPositionY.value = top + (type === "page" ? window.pageYOffset : 0);
  4699. elementHeight.value = height;
  4700. elementWidth.value = width;
  4701. const elX = x.value - elementPositionX.value;
  4702. const elY = y.value - elementPositionY.value;
  4703. isOutside.value = width === 0 || height === 0 || elX < 0 || elY < 0 || elX > width || elY > height;
  4704. if (handleOutside || !isOutside.value) {
  4705. elementX.value = elX;
  4706. elementY.value = elY;
  4707. }
  4708. },
  4709. { immediate: true }
  4710. );
  4711. useEventListener(document, "mouseleave", () => {
  4712. isOutside.value = true;
  4713. });
  4714. }
  4715. return {
  4716. x,
  4717. y,
  4718. sourceType,
  4719. elementX,
  4720. elementY,
  4721. elementPositionX,
  4722. elementPositionY,
  4723. elementHeight,
  4724. elementWidth,
  4725. isOutside,
  4726. stop
  4727. };
  4728. }
  4729. function useMousePressed(options = {}) {
  4730. const {
  4731. touch = true,
  4732. drag = true,
  4733. capture = false,
  4734. initialValue = false,
  4735. window = defaultWindow
  4736. } = options;
  4737. const pressed = vue.ref(initialValue);
  4738. const sourceType = vue.ref(null);
  4739. if (!window) {
  4740. return {
  4741. pressed,
  4742. sourceType
  4743. };
  4744. }
  4745. const onPressed = (srcType) => () => {
  4746. pressed.value = true;
  4747. sourceType.value = srcType;
  4748. };
  4749. const onReleased = () => {
  4750. pressed.value = false;
  4751. sourceType.value = null;
  4752. };
  4753. const target = vue.computed(() => unrefElement(options.target) || window);
  4754. useEventListener(target, "mousedown", onPressed("mouse"), { passive: true, capture });
  4755. useEventListener(window, "mouseleave", onReleased, { passive: true, capture });
  4756. useEventListener(window, "mouseup", onReleased, { passive: true, capture });
  4757. if (drag) {
  4758. useEventListener(target, "dragstart", onPressed("mouse"), { passive: true, capture });
  4759. useEventListener(window, "drop", onReleased, { passive: true, capture });
  4760. useEventListener(window, "dragend", onReleased, { passive: true, capture });
  4761. }
  4762. if (touch) {
  4763. useEventListener(target, "touchstart", onPressed("touch"), { passive: true, capture });
  4764. useEventListener(window, "touchend", onReleased, { passive: true, capture });
  4765. useEventListener(window, "touchcancel", onReleased, { passive: true, capture });
  4766. }
  4767. return {
  4768. pressed,
  4769. sourceType
  4770. };
  4771. }
  4772. function useNavigatorLanguage(options = {}) {
  4773. const { window = defaultWindow } = options;
  4774. const navigator = window == null ? void 0 : window.navigator;
  4775. const isSupported = useSupported(() => navigator && "language" in navigator);
  4776. const language = vue.ref(navigator == null ? void 0 : navigator.language);
  4777. useEventListener(window, "languagechange", () => {
  4778. if (navigator)
  4779. language.value = navigator.language;
  4780. });
  4781. return {
  4782. isSupported,
  4783. language
  4784. };
  4785. }
  4786. function useNetwork(options = {}) {
  4787. const { window = defaultWindow } = options;
  4788. const navigator = window == null ? void 0 : window.navigator;
  4789. const isSupported = useSupported(() => navigator && "connection" in navigator);
  4790. const isOnline = vue.ref(true);
  4791. const saveData = vue.ref(false);
  4792. const offlineAt = vue.ref(void 0);
  4793. const onlineAt = vue.ref(void 0);
  4794. const downlink = vue.ref(void 0);
  4795. const downlinkMax = vue.ref(void 0);
  4796. const rtt = vue.ref(void 0);
  4797. const effectiveType = vue.ref(void 0);
  4798. const type = vue.ref("unknown");
  4799. const connection = isSupported.value && navigator.connection;
  4800. function updateNetworkInformation() {
  4801. if (!navigator)
  4802. return;
  4803. isOnline.value = navigator.onLine;
  4804. offlineAt.value = isOnline.value ? void 0 : Date.now();
  4805. onlineAt.value = isOnline.value ? Date.now() : void 0;
  4806. if (connection) {
  4807. downlink.value = connection.downlink;
  4808. downlinkMax.value = connection.downlinkMax;
  4809. effectiveType.value = connection.effectiveType;
  4810. rtt.value = connection.rtt;
  4811. saveData.value = connection.saveData;
  4812. type.value = connection.type;
  4813. }
  4814. }
  4815. if (window) {
  4816. useEventListener(window, "offline", () => {
  4817. isOnline.value = false;
  4818. offlineAt.value = Date.now();
  4819. });
  4820. useEventListener(window, "online", () => {
  4821. isOnline.value = true;
  4822. onlineAt.value = Date.now();
  4823. });
  4824. }
  4825. if (connection)
  4826. useEventListener(connection, "change", updateNetworkInformation, false);
  4827. updateNetworkInformation();
  4828. return {
  4829. isSupported: vue.readonly(isSupported),
  4830. isOnline: vue.readonly(isOnline),
  4831. saveData: vue.readonly(saveData),
  4832. offlineAt: vue.readonly(offlineAt),
  4833. onlineAt: vue.readonly(onlineAt),
  4834. downlink: vue.readonly(downlink),
  4835. downlinkMax: vue.readonly(downlinkMax),
  4836. effectiveType: vue.readonly(effectiveType),
  4837. rtt: vue.readonly(rtt),
  4838. type: vue.readonly(type)
  4839. };
  4840. }
  4841. function useNow(options = {}) {
  4842. const {
  4843. controls: exposeControls = false,
  4844. interval = "requestAnimationFrame"
  4845. } = options;
  4846. const now = vue.ref(/* @__PURE__ */ new Date());
  4847. const update = () => now.value = /* @__PURE__ */ new Date();
  4848. const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate: true }) : shared.useIntervalFn(update, interval, { immediate: true });
  4849. if (exposeControls) {
  4850. return {
  4851. now,
  4852. ...controls
  4853. };
  4854. } else {
  4855. return now;
  4856. }
  4857. }
  4858. function useObjectUrl(object) {
  4859. const url = vue.ref();
  4860. const release = () => {
  4861. if (url.value)
  4862. URL.revokeObjectURL(url.value);
  4863. url.value = void 0;
  4864. };
  4865. vue.watch(
  4866. () => shared.toValue(object),
  4867. (newObject) => {
  4868. release();
  4869. if (newObject)
  4870. url.value = URL.createObjectURL(newObject);
  4871. },
  4872. { immediate: true }
  4873. );
  4874. shared.tryOnScopeDispose(release);
  4875. return vue.readonly(url);
  4876. }
  4877. function useClamp(value, min, max) {
  4878. if (typeof value === "function" || vue.isReadonly(value))
  4879. return vue.computed(() => shared.clamp(shared.toValue(value), shared.toValue(min), shared.toValue(max)));
  4880. const _value = vue.ref(value);
  4881. return vue.computed({
  4882. get() {
  4883. return _value.value = shared.clamp(_value.value, shared.toValue(min), shared.toValue(max));
  4884. },
  4885. set(value2) {
  4886. _value.value = shared.clamp(value2, shared.toValue(min), shared.toValue(max));
  4887. }
  4888. });
  4889. }
  4890. function useOffsetPagination(options) {
  4891. const {
  4892. total = Number.POSITIVE_INFINITY,
  4893. pageSize = 10,
  4894. page = 1,
  4895. onPageChange = shared.noop,
  4896. onPageSizeChange = shared.noop,
  4897. onPageCountChange = shared.noop
  4898. } = options;
  4899. const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
  4900. const pageCount = vue.computed(() => Math.max(
  4901. 1,
  4902. Math.ceil(shared.toValue(total) / shared.toValue(currentPageSize))
  4903. ));
  4904. const currentPage = useClamp(page, 1, pageCount);
  4905. const isFirstPage = vue.computed(() => currentPage.value === 1);
  4906. const isLastPage = vue.computed(() => currentPage.value === pageCount.value);
  4907. if (vue.isRef(page)) {
  4908. shared.syncRef(page, currentPage, {
  4909. direction: vue.isReadonly(page) ? "ltr" : "both"
  4910. });
  4911. }
  4912. if (vue.isRef(pageSize)) {
  4913. shared.syncRef(pageSize, currentPageSize, {
  4914. direction: vue.isReadonly(pageSize) ? "ltr" : "both"
  4915. });
  4916. }
  4917. function prev() {
  4918. currentPage.value--;
  4919. }
  4920. function next() {
  4921. currentPage.value++;
  4922. }
  4923. const returnValue = {
  4924. currentPage,
  4925. currentPageSize,
  4926. pageCount,
  4927. isFirstPage,
  4928. isLastPage,
  4929. prev,
  4930. next
  4931. };
  4932. vue.watch(currentPage, () => {
  4933. onPageChange(vue.reactive(returnValue));
  4934. });
  4935. vue.watch(currentPageSize, () => {
  4936. onPageSizeChange(vue.reactive(returnValue));
  4937. });
  4938. vue.watch(pageCount, () => {
  4939. onPageCountChange(vue.reactive(returnValue));
  4940. });
  4941. return returnValue;
  4942. }
  4943. function useOnline(options = {}) {
  4944. const { isOnline } = useNetwork(options);
  4945. return isOnline;
  4946. }
  4947. function usePageLeave(options = {}) {
  4948. const { window = defaultWindow } = options;
  4949. const isLeft = vue.ref(false);
  4950. const handler = (event) => {
  4951. if (!window)
  4952. return;
  4953. event = event || window.event;
  4954. const from = event.relatedTarget || event.toElement;
  4955. isLeft.value = !from;
  4956. };
  4957. if (window) {
  4958. useEventListener(window, "mouseout", handler, { passive: true });
  4959. useEventListener(window.document, "mouseleave", handler, { passive: true });
  4960. useEventListener(window.document, "mouseenter", handler, { passive: true });
  4961. }
  4962. return isLeft;
  4963. }
  4964. function useScreenOrientation(options = {}) {
  4965. const {
  4966. window = defaultWindow
  4967. } = options;
  4968. const isSupported = useSupported(() => window && "screen" in window && "orientation" in window.screen);
  4969. const screenOrientation = isSupported.value ? window.screen.orientation : {};
  4970. const orientation = vue.ref(screenOrientation.type);
  4971. const angle = vue.ref(screenOrientation.angle || 0);
  4972. if (isSupported.value) {
  4973. useEventListener(window, "orientationchange", () => {
  4974. orientation.value = screenOrientation.type;
  4975. angle.value = screenOrientation.angle;
  4976. });
  4977. }
  4978. const lockOrientation = (type) => {
  4979. if (isSupported.value && typeof screenOrientation.lock === "function")
  4980. return screenOrientation.lock(type);
  4981. return Promise.reject(new Error("Not supported"));
  4982. };
  4983. const unlockOrientation = () => {
  4984. if (isSupported.value && typeof screenOrientation.unlock === "function")
  4985. screenOrientation.unlock();
  4986. };
  4987. return {
  4988. isSupported,
  4989. orientation,
  4990. angle,
  4991. lockOrientation,
  4992. unlockOrientation
  4993. };
  4994. }
  4995. function useParallax(target, options = {}) {
  4996. const {
  4997. deviceOrientationTiltAdjust = (i) => i,
  4998. deviceOrientationRollAdjust = (i) => i,
  4999. mouseTiltAdjust = (i) => i,
  5000. mouseRollAdjust = (i) => i,
  5001. window = defaultWindow
  5002. } = options;
  5003. const orientation = vue.reactive(useDeviceOrientation({ window }));
  5004. const screenOrientation = vue.reactive(useScreenOrientation({ window }));
  5005. const {
  5006. elementX: x,
  5007. elementY: y,
  5008. elementWidth: width,
  5009. elementHeight: height
  5010. } = useMouseInElement(target, { handleOutside: false, window });
  5011. const source = vue.computed(() => {
  5012. if (orientation.isSupported && (orientation.alpha != null && orientation.alpha !== 0 || orientation.gamma != null && orientation.gamma !== 0)) {
  5013. return "deviceOrientation";
  5014. }
  5015. return "mouse";
  5016. });
  5017. const roll = vue.computed(() => {
  5018. if (source.value === "deviceOrientation") {
  5019. let value;
  5020. switch (screenOrientation.orientation) {
  5021. case "landscape-primary":
  5022. value = orientation.gamma / 90;
  5023. break;
  5024. case "landscape-secondary":
  5025. value = -orientation.gamma / 90;
  5026. break;
  5027. case "portrait-primary":
  5028. value = -orientation.beta / 90;
  5029. break;
  5030. case "portrait-secondary":
  5031. value = orientation.beta / 90;
  5032. break;
  5033. default:
  5034. value = -orientation.beta / 90;
  5035. }
  5036. return deviceOrientationRollAdjust(value);
  5037. } else {
  5038. const value = -(y.value - height.value / 2) / height.value;
  5039. return mouseRollAdjust(value);
  5040. }
  5041. });
  5042. const tilt = vue.computed(() => {
  5043. if (source.value === "deviceOrientation") {
  5044. let value;
  5045. switch (screenOrientation.orientation) {
  5046. case "landscape-primary":
  5047. value = orientation.beta / 90;
  5048. break;
  5049. case "landscape-secondary":
  5050. value = -orientation.beta / 90;
  5051. break;
  5052. case "portrait-primary":
  5053. value = orientation.gamma / 90;
  5054. break;
  5055. case "portrait-secondary":
  5056. value = -orientation.gamma / 90;
  5057. break;
  5058. default:
  5059. value = orientation.gamma / 90;
  5060. }
  5061. return deviceOrientationTiltAdjust(value);
  5062. } else {
  5063. const value = (x.value - width.value / 2) / width.value;
  5064. return mouseTiltAdjust(value);
  5065. }
  5066. });
  5067. return { roll, tilt, source };
  5068. }
  5069. function useParentElement(element = useCurrentElement()) {
  5070. const parentElement = vue.shallowRef();
  5071. const update = () => {
  5072. const el = unrefElement(element);
  5073. if (el)
  5074. parentElement.value = el.parentElement;
  5075. };
  5076. shared.tryOnMounted(update);
  5077. vue.watch(() => shared.toValue(element), update);
  5078. return parentElement;
  5079. }
  5080. function usePerformanceObserver(options, callback) {
  5081. const {
  5082. window = defaultWindow,
  5083. immediate = true,
  5084. ...performanceOptions
  5085. } = options;
  5086. const isSupported = useSupported(() => window && "PerformanceObserver" in window);
  5087. let observer;
  5088. const stop = () => {
  5089. observer == null ? void 0 : observer.disconnect();
  5090. };
  5091. const start = () => {
  5092. if (isSupported.value) {
  5093. stop();
  5094. observer = new PerformanceObserver(callback);
  5095. observer.observe(performanceOptions);
  5096. }
  5097. };
  5098. shared.tryOnScopeDispose(stop);
  5099. if (immediate)
  5100. start();
  5101. return {
  5102. isSupported,
  5103. start,
  5104. stop
  5105. };
  5106. }
  5107. const defaultState = {
  5108. x: 0,
  5109. y: 0,
  5110. pointerId: 0,
  5111. pressure: 0,
  5112. tiltX: 0,
  5113. tiltY: 0,
  5114. width: 0,
  5115. height: 0,
  5116. twist: 0,
  5117. pointerType: null
  5118. };
  5119. const keys = /* @__PURE__ */ Object.keys(defaultState);
  5120. function usePointer(options = {}) {
  5121. const {
  5122. target = defaultWindow
  5123. } = options;
  5124. const isInside = vue.ref(false);
  5125. const state = vue.ref(options.initialValue || {});
  5126. Object.assign(state.value, defaultState, state.value);
  5127. const handler = (event) => {
  5128. isInside.value = true;
  5129. if (options.pointerTypes && !options.pointerTypes.includes(event.pointerType))
  5130. return;
  5131. state.value = shared.objectPick(event, keys, false);
  5132. };
  5133. if (target) {
  5134. const listenerOptions = { passive: true };
  5135. useEventListener(target, ["pointerdown", "pointermove", "pointerup"], handler, listenerOptions);
  5136. useEventListener(target, "pointerleave", () => isInside.value = false, listenerOptions);
  5137. }
  5138. return {
  5139. ...shared.toRefs(state),
  5140. isInside
  5141. };
  5142. }
  5143. function usePointerLock(target, options = {}) {
  5144. const { document = defaultDocument } = options;
  5145. const isSupported = useSupported(() => document && "pointerLockElement" in document);
  5146. const element = vue.ref();
  5147. const triggerElement = vue.ref();
  5148. let targetElement;
  5149. if (isSupported.value) {
  5150. useEventListener(document, "pointerlockchange", () => {
  5151. var _a;
  5152. const currentElement = (_a = document.pointerLockElement) != null ? _a : element.value;
  5153. if (targetElement && currentElement === targetElement) {
  5154. element.value = document.pointerLockElement;
  5155. if (!element.value)
  5156. targetElement = triggerElement.value = null;
  5157. }
  5158. });
  5159. useEventListener(document, "pointerlockerror", () => {
  5160. var _a;
  5161. const currentElement = (_a = document.pointerLockElement) != null ? _a : element.value;
  5162. if (targetElement && currentElement === targetElement) {
  5163. const action = document.pointerLockElement ? "release" : "acquire";
  5164. throw new Error(`Failed to ${action} pointer lock.`);
  5165. }
  5166. });
  5167. }
  5168. async function lock(e) {
  5169. var _a;
  5170. if (!isSupported.value)
  5171. throw new Error("Pointer Lock API is not supported by your browser.");
  5172. triggerElement.value = e instanceof Event ? e.currentTarget : null;
  5173. targetElement = e instanceof Event ? (_a = unrefElement(target)) != null ? _a : triggerElement.value : unrefElement(e);
  5174. if (!targetElement)
  5175. throw new Error("Target element undefined.");
  5176. targetElement.requestPointerLock();
  5177. return await shared.until(element).toBe(targetElement);
  5178. }
  5179. async function unlock() {
  5180. if (!element.value)
  5181. return false;
  5182. document.exitPointerLock();
  5183. await shared.until(element).toBeNull();
  5184. return true;
  5185. }
  5186. return {
  5187. isSupported,
  5188. element,
  5189. triggerElement,
  5190. lock,
  5191. unlock
  5192. };
  5193. }
  5194. function usePointerSwipe(target, options = {}) {
  5195. const targetRef = shared.toRef(target);
  5196. const {
  5197. threshold = 50,
  5198. onSwipe,
  5199. onSwipeEnd,
  5200. onSwipeStart,
  5201. disableTextSelect = false
  5202. } = options;
  5203. const posStart = vue.reactive({ x: 0, y: 0 });
  5204. const updatePosStart = (x, y) => {
  5205. posStart.x = x;
  5206. posStart.y = y;
  5207. };
  5208. const posEnd = vue.reactive({ x: 0, y: 0 });
  5209. const updatePosEnd = (x, y) => {
  5210. posEnd.x = x;
  5211. posEnd.y = y;
  5212. };
  5213. const distanceX = vue.computed(() => posStart.x - posEnd.x);
  5214. const distanceY = vue.computed(() => posStart.y - posEnd.y);
  5215. const { max, abs } = Math;
  5216. const isThresholdExceeded = vue.computed(() => max(abs(distanceX.value), abs(distanceY.value)) >= threshold);
  5217. const isSwiping = vue.ref(false);
  5218. const isPointerDown = vue.ref(false);
  5219. const direction = vue.computed(() => {
  5220. if (!isThresholdExceeded.value)
  5221. return "none";
  5222. if (abs(distanceX.value) > abs(distanceY.value)) {
  5223. return distanceX.value > 0 ? "left" : "right";
  5224. } else {
  5225. return distanceY.value > 0 ? "up" : "down";
  5226. }
  5227. });
  5228. const eventIsAllowed = (e) => {
  5229. var _a, _b, _c;
  5230. const isReleasingButton = e.buttons === 0;
  5231. const isPrimaryButton = e.buttons === 1;
  5232. return (_c = (_b = (_a = options.pointerTypes) == null ? void 0 : _a.includes(e.pointerType)) != null ? _b : isReleasingButton || isPrimaryButton) != null ? _c : true;
  5233. };
  5234. const stops = [
  5235. useEventListener(target, "pointerdown", (e) => {
  5236. if (!eventIsAllowed(e))
  5237. return;
  5238. isPointerDown.value = true;
  5239. const eventTarget = e.target;
  5240. eventTarget == null ? void 0 : eventTarget.setPointerCapture(e.pointerId);
  5241. const { clientX: x, clientY: y } = e;
  5242. updatePosStart(x, y);
  5243. updatePosEnd(x, y);
  5244. onSwipeStart == null ? void 0 : onSwipeStart(e);
  5245. }),
  5246. useEventListener(target, "pointermove", (e) => {
  5247. if (!eventIsAllowed(e))
  5248. return;
  5249. if (!isPointerDown.value)
  5250. return;
  5251. const { clientX: x, clientY: y } = e;
  5252. updatePosEnd(x, y);
  5253. if (!isSwiping.value && isThresholdExceeded.value)
  5254. isSwiping.value = true;
  5255. if (isSwiping.value)
  5256. onSwipe == null ? void 0 : onSwipe(e);
  5257. }),
  5258. useEventListener(target, "pointerup", (e) => {
  5259. if (!eventIsAllowed(e))
  5260. return;
  5261. if (isSwiping.value)
  5262. onSwipeEnd == null ? void 0 : onSwipeEnd(e, direction.value);
  5263. isPointerDown.value = false;
  5264. isSwiping.value = false;
  5265. })
  5266. ];
  5267. shared.tryOnMounted(() => {
  5268. var _a, _b, _c, _d, _e, _f, _g, _h;
  5269. (_b = (_a = targetRef.value) == null ? void 0 : _a.style) == null ? void 0 : _b.setProperty("touch-action", "none");
  5270. if (disableTextSelect) {
  5271. (_d = (_c = targetRef.value) == null ? void 0 : _c.style) == null ? void 0 : _d.setProperty("-webkit-user-select", "none");
  5272. (_f = (_e = targetRef.value) == null ? void 0 : _e.style) == null ? void 0 : _f.setProperty("-ms-user-select", "none");
  5273. (_h = (_g = targetRef.value) == null ? void 0 : _g.style) == null ? void 0 : _h.setProperty("user-select", "none");
  5274. }
  5275. });
  5276. const stop = () => stops.forEach((s) => s());
  5277. return {
  5278. isSwiping: vue.readonly(isSwiping),
  5279. direction: vue.readonly(direction),
  5280. posStart: vue.readonly(posStart),
  5281. posEnd: vue.readonly(posEnd),
  5282. distanceX,
  5283. distanceY,
  5284. stop
  5285. };
  5286. }
  5287. function usePreferredColorScheme(options) {
  5288. const isLight = useMediaQuery("(prefers-color-scheme: light)", options);
  5289. const isDark = useMediaQuery("(prefers-color-scheme: dark)", options);
  5290. return vue.computed(() => {
  5291. if (isDark.value)
  5292. return "dark";
  5293. if (isLight.value)
  5294. return "light";
  5295. return "no-preference";
  5296. });
  5297. }
  5298. function usePreferredContrast(options) {
  5299. const isMore = useMediaQuery("(prefers-contrast: more)", options);
  5300. const isLess = useMediaQuery("(prefers-contrast: less)", options);
  5301. const isCustom = useMediaQuery("(prefers-contrast: custom)", options);
  5302. return vue.computed(() => {
  5303. if (isMore.value)
  5304. return "more";
  5305. if (isLess.value)
  5306. return "less";
  5307. if (isCustom.value)
  5308. return "custom";
  5309. return "no-preference";
  5310. });
  5311. }
  5312. function usePreferredLanguages(options = {}) {
  5313. const { window = defaultWindow } = options;
  5314. if (!window)
  5315. return vue.ref(["en"]);
  5316. const navigator = window.navigator;
  5317. const value = vue.ref(navigator.languages);
  5318. useEventListener(window, "languagechange", () => {
  5319. value.value = navigator.languages;
  5320. });
  5321. return value;
  5322. }
  5323. function usePreferredReducedMotion(options) {
  5324. const isReduced = useMediaQuery("(prefers-reduced-motion: reduce)", options);
  5325. return vue.computed(() => {
  5326. if (isReduced.value)
  5327. return "reduce";
  5328. return "no-preference";
  5329. });
  5330. }
  5331. function usePrevious(value, initialValue) {
  5332. const previous = vue.shallowRef(initialValue);
  5333. vue.watch(
  5334. shared.toRef(value),
  5335. (_, oldValue) => {
  5336. previous.value = oldValue;
  5337. },
  5338. { flush: "sync" }
  5339. );
  5340. return vue.readonly(previous);
  5341. }
  5342. const topVarName = "--vueuse-safe-area-top";
  5343. const rightVarName = "--vueuse-safe-area-right";
  5344. const bottomVarName = "--vueuse-safe-area-bottom";
  5345. const leftVarName = "--vueuse-safe-area-left";
  5346. function useScreenSafeArea() {
  5347. const top = vue.ref("");
  5348. const right = vue.ref("");
  5349. const bottom = vue.ref("");
  5350. const left = vue.ref("");
  5351. if (shared.isClient) {
  5352. const topCssVar = useCssVar(topVarName);
  5353. const rightCssVar = useCssVar(rightVarName);
  5354. const bottomCssVar = useCssVar(bottomVarName);
  5355. const leftCssVar = useCssVar(leftVarName);
  5356. topCssVar.value = "env(safe-area-inset-top, 0px)";
  5357. rightCssVar.value = "env(safe-area-inset-right, 0px)";
  5358. bottomCssVar.value = "env(safe-area-inset-bottom, 0px)";
  5359. leftCssVar.value = "env(safe-area-inset-left, 0px)";
  5360. update();
  5361. useEventListener("resize", shared.useDebounceFn(update));
  5362. }
  5363. function update() {
  5364. top.value = getValue(topVarName);
  5365. right.value = getValue(rightVarName);
  5366. bottom.value = getValue(bottomVarName);
  5367. left.value = getValue(leftVarName);
  5368. }
  5369. return {
  5370. top,
  5371. right,
  5372. bottom,
  5373. left,
  5374. update
  5375. };
  5376. }
  5377. function getValue(position) {
  5378. return getComputedStyle(document.documentElement).getPropertyValue(position);
  5379. }
  5380. function useScriptTag(src, onLoaded = shared.noop, options = {}) {
  5381. const {
  5382. immediate = true,
  5383. manual = false,
  5384. type = "text/javascript",
  5385. async = true,
  5386. crossOrigin,
  5387. referrerPolicy,
  5388. noModule,
  5389. defer,
  5390. document = defaultDocument,
  5391. attrs = {}
  5392. } = options;
  5393. const scriptTag = vue.ref(null);
  5394. let _promise = null;
  5395. const loadScript = (waitForScriptLoad) => new Promise((resolve, reject) => {
  5396. const resolveWithElement = (el2) => {
  5397. scriptTag.value = el2;
  5398. resolve(el2);
  5399. return el2;
  5400. };
  5401. if (!document) {
  5402. resolve(false);
  5403. return;
  5404. }
  5405. let shouldAppend = false;
  5406. let el = document.querySelector(`script[src="${shared.toValue(src)}"]`);
  5407. if (!el) {
  5408. el = document.createElement("script");
  5409. el.type = type;
  5410. el.async = async;
  5411. el.src = shared.toValue(src);
  5412. if (defer)
  5413. el.defer = defer;
  5414. if (crossOrigin)
  5415. el.crossOrigin = crossOrigin;
  5416. if (noModule)
  5417. el.noModule = noModule;
  5418. if (referrerPolicy)
  5419. el.referrerPolicy = referrerPolicy;
  5420. Object.entries(attrs).forEach(([name, value]) => el == null ? void 0 : el.setAttribute(name, value));
  5421. shouldAppend = true;
  5422. } else if (el.hasAttribute("data-loaded")) {
  5423. resolveWithElement(el);
  5424. }
  5425. el.addEventListener("error", (event) => reject(event));
  5426. el.addEventListener("abort", (event) => reject(event));
  5427. el.addEventListener("load", () => {
  5428. el.setAttribute("data-loaded", "true");
  5429. onLoaded(el);
  5430. resolveWithElement(el);
  5431. });
  5432. if (shouldAppend)
  5433. el = document.head.appendChild(el);
  5434. if (!waitForScriptLoad)
  5435. resolveWithElement(el);
  5436. });
  5437. const load = (waitForScriptLoad = true) => {
  5438. if (!_promise)
  5439. _promise = loadScript(waitForScriptLoad);
  5440. return _promise;
  5441. };
  5442. const unload = () => {
  5443. if (!document)
  5444. return;
  5445. _promise = null;
  5446. if (scriptTag.value)
  5447. scriptTag.value = null;
  5448. const el = document.querySelector(`script[src="${shared.toValue(src)}"]`);
  5449. if (el)
  5450. document.head.removeChild(el);
  5451. };
  5452. if (immediate && !manual)
  5453. shared.tryOnMounted(load);
  5454. if (!manual)
  5455. shared.tryOnUnmounted(unload);
  5456. return { scriptTag, load, unload };
  5457. }
  5458. function checkOverflowScroll(ele) {
  5459. const style = window.getComputedStyle(ele);
  5460. if (style.overflowX === "scroll" || style.overflowY === "scroll" || style.overflowX === "auto" && ele.clientWidth < ele.scrollWidth || style.overflowY === "auto" && ele.clientHeight < ele.scrollHeight) {
  5461. return true;
  5462. } else {
  5463. const parent = ele.parentNode;
  5464. if (!parent || parent.tagName === "BODY")
  5465. return false;
  5466. return checkOverflowScroll(parent);
  5467. }
  5468. }
  5469. function preventDefault(rawEvent) {
  5470. const e = rawEvent || window.event;
  5471. const _target = e.target;
  5472. if (checkOverflowScroll(_target))
  5473. return false;
  5474. if (e.touches.length > 1)
  5475. return true;
  5476. if (e.preventDefault)
  5477. e.preventDefault();
  5478. return false;
  5479. }
  5480. const elInitialOverflow = /* @__PURE__ */ new WeakMap();
  5481. function useScrollLock(element, initialState = false) {
  5482. const isLocked = vue.ref(initialState);
  5483. let stopTouchMoveListener = null;
  5484. let initialOverflow = "";
  5485. vue.watch(shared.toRef(element), (el) => {
  5486. const target = resolveElement(shared.toValue(el));
  5487. if (target) {
  5488. const ele = target;
  5489. if (!elInitialOverflow.get(ele))
  5490. elInitialOverflow.set(ele, ele.style.overflow);
  5491. if (ele.style.overflow !== "hidden")
  5492. initialOverflow = ele.style.overflow;
  5493. if (ele.style.overflow === "hidden")
  5494. return isLocked.value = true;
  5495. if (isLocked.value)
  5496. return ele.style.overflow = "hidden";
  5497. }
  5498. }, {
  5499. immediate: true
  5500. });
  5501. const lock = () => {
  5502. const el = resolveElement(shared.toValue(element));
  5503. if (!el || isLocked.value)
  5504. return;
  5505. if (shared.isIOS) {
  5506. stopTouchMoveListener = useEventListener(
  5507. el,
  5508. "touchmove",
  5509. (e) => {
  5510. preventDefault(e);
  5511. },
  5512. { passive: false }
  5513. );
  5514. }
  5515. el.style.overflow = "hidden";
  5516. isLocked.value = true;
  5517. };
  5518. const unlock = () => {
  5519. const el = resolveElement(shared.toValue(element));
  5520. if (!el || !isLocked.value)
  5521. return;
  5522. if (shared.isIOS)
  5523. stopTouchMoveListener == null ? void 0 : stopTouchMoveListener();
  5524. el.style.overflow = initialOverflow;
  5525. elInitialOverflow.delete(el);
  5526. isLocked.value = false;
  5527. };
  5528. shared.tryOnScopeDispose(unlock);
  5529. return vue.computed({
  5530. get() {
  5531. return isLocked.value;
  5532. },
  5533. set(v) {
  5534. if (v)
  5535. lock();
  5536. else unlock();
  5537. }
  5538. });
  5539. }
  5540. function useSessionStorage(key, initialValue, options = {}) {
  5541. const { window = defaultWindow } = options;
  5542. return useStorage(key, initialValue, window == null ? void 0 : window.sessionStorage, options);
  5543. }
  5544. function useShare(shareOptions = {}, options = {}) {
  5545. const { navigator = defaultNavigator } = options;
  5546. const _navigator = navigator;
  5547. const isSupported = useSupported(() => _navigator && "canShare" in _navigator);
  5548. const share = async (overrideOptions = {}) => {
  5549. if (isSupported.value) {
  5550. const data = {
  5551. ...shared.toValue(shareOptions),
  5552. ...shared.toValue(overrideOptions)
  5553. };
  5554. let granted = true;
  5555. if (data.files && _navigator.canShare)
  5556. granted = _navigator.canShare({ files: data.files });
  5557. if (granted)
  5558. return _navigator.share(data);
  5559. }
  5560. };
  5561. return {
  5562. isSupported,
  5563. share
  5564. };
  5565. }
  5566. const defaultSortFn = (source, compareFn) => source.sort(compareFn);
  5567. const defaultCompare = (a, b) => a - b;
  5568. function useSorted(...args) {
  5569. var _a, _b, _c, _d;
  5570. const [source] = args;
  5571. let compareFn = defaultCompare;
  5572. let options = {};
  5573. if (args.length === 2) {
  5574. if (typeof args[1] === "object") {
  5575. options = args[1];
  5576. compareFn = (_a = options.compareFn) != null ? _a : defaultCompare;
  5577. } else {
  5578. compareFn = (_b = args[1]) != null ? _b : defaultCompare;
  5579. }
  5580. } else if (args.length > 2) {
  5581. compareFn = (_c = args[1]) != null ? _c : defaultCompare;
  5582. options = (_d = args[2]) != null ? _d : {};
  5583. }
  5584. const {
  5585. dirty = false,
  5586. sortFn = defaultSortFn
  5587. } = options;
  5588. if (!dirty)
  5589. return vue.computed(() => sortFn([...shared.toValue(source)], compareFn));
  5590. vue.watchEffect(() => {
  5591. const result = sortFn(shared.toValue(source), compareFn);
  5592. if (vue.isRef(source))
  5593. source.value = result;
  5594. else
  5595. source.splice(0, source.length, ...result);
  5596. });
  5597. return source;
  5598. }
  5599. function useSpeechRecognition(options = {}) {
  5600. const {
  5601. interimResults = true,
  5602. continuous = true,
  5603. maxAlternatives = 1,
  5604. window = defaultWindow
  5605. } = options;
  5606. const lang = shared.toRef(options.lang || "en-US");
  5607. const isListening = vue.ref(false);
  5608. const isFinal = vue.ref(false);
  5609. const result = vue.ref("");
  5610. const error = vue.shallowRef(void 0);
  5611. const toggle = (value = !isListening.value) => {
  5612. isListening.value = value;
  5613. };
  5614. const start = () => {
  5615. isListening.value = true;
  5616. };
  5617. const stop = () => {
  5618. isListening.value = false;
  5619. };
  5620. const SpeechRecognition = window && (window.SpeechRecognition || window.webkitSpeechRecognition);
  5621. const isSupported = useSupported(() => SpeechRecognition);
  5622. let recognition;
  5623. if (isSupported.value) {
  5624. recognition = new SpeechRecognition();
  5625. recognition.continuous = continuous;
  5626. recognition.interimResults = interimResults;
  5627. recognition.lang = shared.toValue(lang);
  5628. recognition.maxAlternatives = maxAlternatives;
  5629. recognition.onstart = () => {
  5630. isFinal.value = false;
  5631. };
  5632. vue.watch(lang, (lang2) => {
  5633. if (recognition && !isListening.value)
  5634. recognition.lang = lang2;
  5635. });
  5636. recognition.onresult = (event) => {
  5637. const currentResult = event.results[event.resultIndex];
  5638. const { transcript } = currentResult[0];
  5639. isFinal.value = currentResult.isFinal;
  5640. result.value = transcript;
  5641. error.value = void 0;
  5642. };
  5643. recognition.onerror = (event) => {
  5644. error.value = event;
  5645. };
  5646. recognition.onend = () => {
  5647. isListening.value = false;
  5648. recognition.lang = shared.toValue(lang);
  5649. };
  5650. vue.watch(isListening, () => {
  5651. if (isListening.value)
  5652. recognition.start();
  5653. else
  5654. recognition.stop();
  5655. });
  5656. }
  5657. shared.tryOnScopeDispose(() => {
  5658. isListening.value = false;
  5659. });
  5660. return {
  5661. isSupported,
  5662. isListening,
  5663. isFinal,
  5664. recognition,
  5665. result,
  5666. error,
  5667. toggle,
  5668. start,
  5669. stop
  5670. };
  5671. }
  5672. function useSpeechSynthesis(text, options = {}) {
  5673. const {
  5674. pitch = 1,
  5675. rate = 1,
  5676. volume = 1,
  5677. window = defaultWindow
  5678. } = options;
  5679. const synth = window && window.speechSynthesis;
  5680. const isSupported = useSupported(() => synth);
  5681. const isPlaying = vue.ref(false);
  5682. const status = vue.ref("init");
  5683. const spokenText = shared.toRef(text || "");
  5684. const lang = shared.toRef(options.lang || "en-US");
  5685. const error = vue.shallowRef(void 0);
  5686. const toggle = (value = !isPlaying.value) => {
  5687. isPlaying.value = value;
  5688. };
  5689. const bindEventsForUtterance = (utterance2) => {
  5690. utterance2.lang = shared.toValue(lang);
  5691. utterance2.voice = shared.toValue(options.voice) || null;
  5692. utterance2.pitch = shared.toValue(pitch);
  5693. utterance2.rate = shared.toValue(rate);
  5694. utterance2.volume = volume;
  5695. utterance2.onstart = () => {
  5696. isPlaying.value = true;
  5697. status.value = "play";
  5698. };
  5699. utterance2.onpause = () => {
  5700. isPlaying.value = false;
  5701. status.value = "pause";
  5702. };
  5703. utterance2.onresume = () => {
  5704. isPlaying.value = true;
  5705. status.value = "play";
  5706. };
  5707. utterance2.onend = () => {
  5708. isPlaying.value = false;
  5709. status.value = "end";
  5710. };
  5711. utterance2.onerror = (event) => {
  5712. error.value = event;
  5713. };
  5714. };
  5715. const utterance = vue.computed(() => {
  5716. isPlaying.value = false;
  5717. status.value = "init";
  5718. const newUtterance = new SpeechSynthesisUtterance(spokenText.value);
  5719. bindEventsForUtterance(newUtterance);
  5720. return newUtterance;
  5721. });
  5722. const speak = () => {
  5723. synth.cancel();
  5724. if (utterance)
  5725. synth.speak(utterance.value);
  5726. };
  5727. const stop = () => {
  5728. synth.cancel();
  5729. isPlaying.value = false;
  5730. };
  5731. if (isSupported.value) {
  5732. bindEventsForUtterance(utterance.value);
  5733. vue.watch(lang, (lang2) => {
  5734. if (utterance.value && !isPlaying.value)
  5735. utterance.value.lang = lang2;
  5736. });
  5737. if (options.voice) {
  5738. vue.watch(options.voice, () => {
  5739. synth.cancel();
  5740. });
  5741. }
  5742. vue.watch(isPlaying, () => {
  5743. if (isPlaying.value)
  5744. synth.resume();
  5745. else
  5746. synth.pause();
  5747. });
  5748. }
  5749. shared.tryOnScopeDispose(() => {
  5750. isPlaying.value = false;
  5751. });
  5752. return {
  5753. isSupported,
  5754. isPlaying,
  5755. status,
  5756. utterance,
  5757. error,
  5758. stop,
  5759. toggle,
  5760. speak
  5761. };
  5762. }
  5763. function useStepper(steps, initialStep) {
  5764. const stepsRef = vue.ref(steps);
  5765. const stepNames = vue.computed(() => Array.isArray(stepsRef.value) ? stepsRef.value : Object.keys(stepsRef.value));
  5766. const index = vue.ref(stepNames.value.indexOf(initialStep != null ? initialStep : stepNames.value[0]));
  5767. const current = vue.computed(() => at(index.value));
  5768. const isFirst = vue.computed(() => index.value === 0);
  5769. const isLast = vue.computed(() => index.value === stepNames.value.length - 1);
  5770. const next = vue.computed(() => stepNames.value[index.value + 1]);
  5771. const previous = vue.computed(() => stepNames.value[index.value - 1]);
  5772. function at(index2) {
  5773. if (Array.isArray(stepsRef.value))
  5774. return stepsRef.value[index2];
  5775. return stepsRef.value[stepNames.value[index2]];
  5776. }
  5777. function get(step) {
  5778. if (!stepNames.value.includes(step))
  5779. return;
  5780. return at(stepNames.value.indexOf(step));
  5781. }
  5782. function goTo(step) {
  5783. if (stepNames.value.includes(step))
  5784. index.value = stepNames.value.indexOf(step);
  5785. }
  5786. function goToNext() {
  5787. if (isLast.value)
  5788. return;
  5789. index.value++;
  5790. }
  5791. function goToPrevious() {
  5792. if (isFirst.value)
  5793. return;
  5794. index.value--;
  5795. }
  5796. function goBackTo(step) {
  5797. if (isAfter(step))
  5798. goTo(step);
  5799. }
  5800. function isNext(step) {
  5801. return stepNames.value.indexOf(step) === index.value + 1;
  5802. }
  5803. function isPrevious(step) {
  5804. return stepNames.value.indexOf(step) === index.value - 1;
  5805. }
  5806. function isCurrent(step) {
  5807. return stepNames.value.indexOf(step) === index.value;
  5808. }
  5809. function isBefore(step) {
  5810. return index.value < stepNames.value.indexOf(step);
  5811. }
  5812. function isAfter(step) {
  5813. return index.value > stepNames.value.indexOf(step);
  5814. }
  5815. return {
  5816. steps: stepsRef,
  5817. stepNames,
  5818. index,
  5819. current,
  5820. next,
  5821. previous,
  5822. isFirst,
  5823. isLast,
  5824. at,
  5825. get,
  5826. goTo,
  5827. goToNext,
  5828. goToPrevious,
  5829. goBackTo,
  5830. isNext,
  5831. isPrevious,
  5832. isCurrent,
  5833. isBefore,
  5834. isAfter
  5835. };
  5836. }
  5837. function useStorageAsync(key, initialValue, storage, options = {}) {
  5838. var _a;
  5839. const {
  5840. flush = "pre",
  5841. deep = true,
  5842. listenToStorageChanges = true,
  5843. writeDefaults = true,
  5844. mergeDefaults = false,
  5845. shallow,
  5846. window = defaultWindow,
  5847. eventFilter,
  5848. onError = (e) => {
  5849. console.error(e);
  5850. }
  5851. } = options;
  5852. const rawInit = shared.toValue(initialValue);
  5853. const type = guessSerializerType(rawInit);
  5854. const data = (shallow ? vue.shallowRef : vue.ref)(initialValue);
  5855. const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
  5856. if (!storage) {
  5857. try {
  5858. storage = getSSRHandler("getDefaultStorageAsync", () => {
  5859. var _a2;
  5860. return (_a2 = defaultWindow) == null ? void 0 : _a2.localStorage;
  5861. })();
  5862. } catch (e) {
  5863. onError(e);
  5864. }
  5865. }
  5866. async function read(event) {
  5867. if (!storage || event && event.key !== key)
  5868. return;
  5869. try {
  5870. const rawValue = event ? event.newValue : await storage.getItem(key);
  5871. if (rawValue == null) {
  5872. data.value = rawInit;
  5873. if (writeDefaults && rawInit !== null)
  5874. await storage.setItem(key, await serializer.write(rawInit));
  5875. } else if (mergeDefaults) {
  5876. const value = await serializer.read(rawValue);
  5877. if (typeof mergeDefaults === "function")
  5878. data.value = mergeDefaults(value, rawInit);
  5879. else if (type === "object" && !Array.isArray(value))
  5880. data.value = { ...rawInit, ...value };
  5881. else data.value = value;
  5882. } else {
  5883. data.value = await serializer.read(rawValue);
  5884. }
  5885. } catch (e) {
  5886. onError(e);
  5887. }
  5888. }
  5889. read();
  5890. if (window && listenToStorageChanges)
  5891. useEventListener(window, "storage", (e) => Promise.resolve().then(() => read(e)));
  5892. if (storage) {
  5893. shared.watchWithFilter(
  5894. data,
  5895. async () => {
  5896. try {
  5897. if (data.value == null)
  5898. await storage.removeItem(key);
  5899. else
  5900. await storage.setItem(key, await serializer.write(data.value));
  5901. } catch (e) {
  5902. onError(e);
  5903. }
  5904. },
  5905. {
  5906. flush,
  5907. deep,
  5908. eventFilter
  5909. }
  5910. );
  5911. }
  5912. return data;
  5913. }
  5914. let _id = 0;
  5915. function useStyleTag(css, options = {}) {
  5916. const isLoaded = vue.ref(false);
  5917. const {
  5918. document = defaultDocument,
  5919. immediate = true,
  5920. manual = false,
  5921. id = `vueuse_styletag_${++_id}`
  5922. } = options;
  5923. const cssRef = vue.ref(css);
  5924. let stop = () => {
  5925. };
  5926. const load = () => {
  5927. if (!document)
  5928. return;
  5929. const el = document.getElementById(id) || document.createElement("style");
  5930. if (!el.isConnected) {
  5931. el.id = id;
  5932. if (options.media)
  5933. el.media = options.media;
  5934. document.head.appendChild(el);
  5935. }
  5936. if (isLoaded.value)
  5937. return;
  5938. stop = vue.watch(
  5939. cssRef,
  5940. (value) => {
  5941. el.textContent = value;
  5942. },
  5943. { immediate: true }
  5944. );
  5945. isLoaded.value = true;
  5946. };
  5947. const unload = () => {
  5948. if (!document || !isLoaded.value)
  5949. return;
  5950. stop();
  5951. document.head.removeChild(document.getElementById(id));
  5952. isLoaded.value = false;
  5953. };
  5954. if (immediate && !manual)
  5955. shared.tryOnMounted(load);
  5956. if (!manual)
  5957. shared.tryOnScopeDispose(unload);
  5958. return {
  5959. id,
  5960. css: cssRef,
  5961. unload,
  5962. load,
  5963. isLoaded: vue.readonly(isLoaded)
  5964. };
  5965. }
  5966. function useSwipe(target, options = {}) {
  5967. const {
  5968. threshold = 50,
  5969. onSwipe,
  5970. onSwipeEnd,
  5971. onSwipeStart,
  5972. passive = true,
  5973. window = defaultWindow
  5974. } = options;
  5975. const coordsStart = vue.reactive({ x: 0, y: 0 });
  5976. const coordsEnd = vue.reactive({ x: 0, y: 0 });
  5977. const diffX = vue.computed(() => coordsStart.x - coordsEnd.x);
  5978. const diffY = vue.computed(() => coordsStart.y - coordsEnd.y);
  5979. const { max, abs } = Math;
  5980. const isThresholdExceeded = vue.computed(() => max(abs(diffX.value), abs(diffY.value)) >= threshold);
  5981. const isSwiping = vue.ref(false);
  5982. const direction = vue.computed(() => {
  5983. if (!isThresholdExceeded.value)
  5984. return "none";
  5985. if (abs(diffX.value) > abs(diffY.value)) {
  5986. return diffX.value > 0 ? "left" : "right";
  5987. } else {
  5988. return diffY.value > 0 ? "up" : "down";
  5989. }
  5990. });
  5991. const getTouchEventCoords = (e) => [e.touches[0].clientX, e.touches[0].clientY];
  5992. const updateCoordsStart = (x, y) => {
  5993. coordsStart.x = x;
  5994. coordsStart.y = y;
  5995. };
  5996. const updateCoordsEnd = (x, y) => {
  5997. coordsEnd.x = x;
  5998. coordsEnd.y = y;
  5999. };
  6000. let listenerOptions;
  6001. const isPassiveEventSupported = checkPassiveEventSupport(window == null ? void 0 : window.document);
  6002. if (!passive)
  6003. listenerOptions = isPassiveEventSupported ? { passive: false, capture: true } : { capture: true };
  6004. else
  6005. listenerOptions = isPassiveEventSupported ? { passive: true } : { capture: false };
  6006. const onTouchEnd = (e) => {
  6007. if (isSwiping.value)
  6008. onSwipeEnd == null ? void 0 : onSwipeEnd(e, direction.value);
  6009. isSwiping.value = false;
  6010. };
  6011. const stops = [
  6012. useEventListener(target, "touchstart", (e) => {
  6013. if (e.touches.length !== 1)
  6014. return;
  6015. const [x, y] = getTouchEventCoords(e);
  6016. updateCoordsStart(x, y);
  6017. updateCoordsEnd(x, y);
  6018. onSwipeStart == null ? void 0 : onSwipeStart(e);
  6019. }, listenerOptions),
  6020. useEventListener(target, "touchmove", (e) => {
  6021. if (e.touches.length !== 1)
  6022. return;
  6023. const [x, y] = getTouchEventCoords(e);
  6024. updateCoordsEnd(x, y);
  6025. if (listenerOptions.capture && !listenerOptions.passive && Math.abs(diffX.value) > Math.abs(diffY.value))
  6026. e.preventDefault();
  6027. if (!isSwiping.value && isThresholdExceeded.value)
  6028. isSwiping.value = true;
  6029. if (isSwiping.value)
  6030. onSwipe == null ? void 0 : onSwipe(e);
  6031. }, listenerOptions),
  6032. useEventListener(target, ["touchend", "touchcancel"], onTouchEnd, listenerOptions)
  6033. ];
  6034. const stop = () => stops.forEach((s) => s());
  6035. return {
  6036. isPassiveEventSupported,
  6037. isSwiping,
  6038. direction,
  6039. coordsStart,
  6040. coordsEnd,
  6041. lengthX: diffX,
  6042. lengthY: diffY,
  6043. stop
  6044. };
  6045. }
  6046. function checkPassiveEventSupport(document) {
  6047. if (!document)
  6048. return false;
  6049. let supportsPassive = false;
  6050. const optionsBlock = {
  6051. get passive() {
  6052. supportsPassive = true;
  6053. return false;
  6054. }
  6055. };
  6056. document.addEventListener("x", shared.noop, optionsBlock);
  6057. document.removeEventListener("x", shared.noop);
  6058. return supportsPassive;
  6059. }
  6060. function useTemplateRefsList() {
  6061. const refs = vue.ref([]);
  6062. refs.value.set = (el) => {
  6063. if (el)
  6064. refs.value.push(el);
  6065. };
  6066. vue.onBeforeUpdate(() => {
  6067. refs.value.length = 0;
  6068. });
  6069. return refs;
  6070. }
  6071. function useTextDirection(options = {}) {
  6072. const {
  6073. document = defaultDocument,
  6074. selector = "html",
  6075. observe = false,
  6076. initialValue = "ltr"
  6077. } = options;
  6078. function getValue() {
  6079. var _a, _b;
  6080. return (_b = (_a = document == null ? void 0 : document.querySelector(selector)) == null ? void 0 : _a.getAttribute("dir")) != null ? _b : initialValue;
  6081. }
  6082. const dir = vue.ref(getValue());
  6083. shared.tryOnMounted(() => dir.value = getValue());
  6084. if (observe && document) {
  6085. useMutationObserver(
  6086. document.querySelector(selector),
  6087. () => dir.value = getValue(),
  6088. { attributes: true }
  6089. );
  6090. }
  6091. return vue.computed({
  6092. get() {
  6093. return dir.value;
  6094. },
  6095. set(v) {
  6096. var _a, _b;
  6097. dir.value = v;
  6098. if (!document)
  6099. return;
  6100. if (dir.value)
  6101. (_a = document.querySelector(selector)) == null ? void 0 : _a.setAttribute("dir", dir.value);
  6102. else
  6103. (_b = document.querySelector(selector)) == null ? void 0 : _b.removeAttribute("dir");
  6104. }
  6105. });
  6106. }
  6107. function getRangesFromSelection(selection) {
  6108. var _a;
  6109. const rangeCount = (_a = selection.rangeCount) != null ? _a : 0;
  6110. return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i));
  6111. }
  6112. function useTextSelection(options = {}) {
  6113. const {
  6114. window = defaultWindow
  6115. } = options;
  6116. const selection = vue.ref(null);
  6117. const text = vue.computed(() => {
  6118. var _a, _b;
  6119. return (_b = (_a = selection.value) == null ? void 0 : _a.toString()) != null ? _b : "";
  6120. });
  6121. const ranges = vue.computed(() => selection.value ? getRangesFromSelection(selection.value) : []);
  6122. const rects = vue.computed(() => ranges.value.map((range) => range.getBoundingClientRect()));
  6123. function onSelectionChange() {
  6124. selection.value = null;
  6125. if (window)
  6126. selection.value = window.getSelection();
  6127. }
  6128. if (window)
  6129. useEventListener(window.document, "selectionchange", onSelectionChange);
  6130. return {
  6131. text,
  6132. rects,
  6133. ranges,
  6134. selection
  6135. };
  6136. }
  6137. function useTextareaAutosize(options) {
  6138. var _a;
  6139. const textarea = vue.ref(options == null ? void 0 : options.element);
  6140. const input = vue.ref(options == null ? void 0 : options.input);
  6141. const styleProp = (_a = options == null ? void 0 : options.styleProp) != null ? _a : "height";
  6142. const textareaScrollHeight = vue.ref(1);
  6143. const textareaOldWidth = vue.ref(0);
  6144. function triggerResize() {
  6145. var _a2;
  6146. if (!textarea.value)
  6147. return;
  6148. let height = "";
  6149. textarea.value.style[styleProp] = "1px";
  6150. textareaScrollHeight.value = (_a2 = textarea.value) == null ? void 0 : _a2.scrollHeight;
  6151. const _styleTarget = shared.toValue(options == null ? void 0 : options.styleTarget);
  6152. if (_styleTarget)
  6153. _styleTarget.style[styleProp] = `${textareaScrollHeight.value}px`;
  6154. else
  6155. height = `${textareaScrollHeight.value}px`;
  6156. textarea.value.style[styleProp] = height;
  6157. }
  6158. vue.watch([input, textarea], () => vue.nextTick(triggerResize), { immediate: true });
  6159. vue.watch(textareaScrollHeight, () => {
  6160. var _a2;
  6161. return (_a2 = options == null ? void 0 : options.onResize) == null ? void 0 : _a2.call(options);
  6162. });
  6163. useResizeObserver(textarea, ([{ contentRect }]) => {
  6164. if (textareaOldWidth.value === contentRect.width)
  6165. return;
  6166. textareaOldWidth.value = contentRect.width;
  6167. triggerResize();
  6168. });
  6169. if (options == null ? void 0 : options.watch)
  6170. vue.watch(options.watch, triggerResize, { immediate: true, deep: true });
  6171. return {
  6172. textarea,
  6173. input,
  6174. triggerResize
  6175. };
  6176. }
  6177. function useThrottledRefHistory(source, options = {}) {
  6178. const { throttle = 200, trailing = true } = options;
  6179. const filter = shared.throttleFilter(throttle, trailing);
  6180. const history = useRefHistory(source, { ...options, eventFilter: filter });
  6181. return {
  6182. ...history
  6183. };
  6184. }
  6185. const DEFAULT_UNITS = [
  6186. { max: 6e4, value: 1e3, name: "second" },
  6187. { max: 276e4, value: 6e4, name: "minute" },
  6188. { max: 72e6, value: 36e5, name: "hour" },
  6189. { max: 5184e5, value: 864e5, name: "day" },
  6190. { max: 24192e5, value: 6048e5, name: "week" },
  6191. { max: 28512e6, value: 2592e6, name: "month" },
  6192. { max: Number.POSITIVE_INFINITY, value: 31536e6, name: "year" }
  6193. ];
  6194. const DEFAULT_MESSAGES = {
  6195. justNow: "just now",
  6196. past: (n) => n.match(/\d/) ? `${n} ago` : n,
  6197. future: (n) => n.match(/\d/) ? `in ${n}` : n,
  6198. month: (n, past) => n === 1 ? past ? "last month" : "next month" : `${n} month${n > 1 ? "s" : ""}`,
  6199. year: (n, past) => n === 1 ? past ? "last year" : "next year" : `${n} year${n > 1 ? "s" : ""}`,
  6200. day: (n, past) => n === 1 ? past ? "yesterday" : "tomorrow" : `${n} day${n > 1 ? "s" : ""}`,
  6201. week: (n, past) => n === 1 ? past ? "last week" : "next week" : `${n} week${n > 1 ? "s" : ""}`,
  6202. hour: (n) => `${n} hour${n > 1 ? "s" : ""}`,
  6203. minute: (n) => `${n} minute${n > 1 ? "s" : ""}`,
  6204. second: (n) => `${n} second${n > 1 ? "s" : ""}`,
  6205. invalid: ""
  6206. };
  6207. function DEFAULT_FORMATTER(date) {
  6208. return date.toISOString().slice(0, 10);
  6209. }
  6210. function useTimeAgo(time, options = {}) {
  6211. const {
  6212. controls: exposeControls = false,
  6213. updateInterval = 3e4
  6214. } = options;
  6215. const { now, ...controls } = useNow({ interval: updateInterval, controls: true });
  6216. const timeAgo = vue.computed(() => formatTimeAgo(new Date(shared.toValue(time)), options, shared.toValue(now)));
  6217. if (exposeControls) {
  6218. return {
  6219. timeAgo,
  6220. ...controls
  6221. };
  6222. } else {
  6223. return timeAgo;
  6224. }
  6225. }
  6226. function formatTimeAgo(from, options = {}, now = Date.now()) {
  6227. var _a;
  6228. const {
  6229. max,
  6230. messages = DEFAULT_MESSAGES,
  6231. fullDateFormatter = DEFAULT_FORMATTER,
  6232. units = DEFAULT_UNITS,
  6233. showSecond = false,
  6234. rounding = "round"
  6235. } = options;
  6236. const roundFn = typeof rounding === "number" ? (n) => +n.toFixed(rounding) : Math[rounding];
  6237. const diff = +now - +from;
  6238. const absDiff = Math.abs(diff);
  6239. function getValue(diff2, unit) {
  6240. return roundFn(Math.abs(diff2) / unit.value);
  6241. }
  6242. function format(diff2, unit) {
  6243. const val = getValue(diff2, unit);
  6244. const past = diff2 > 0;
  6245. const str = applyFormat(unit.name, val, past);
  6246. return applyFormat(past ? "past" : "future", str, past);
  6247. }
  6248. function applyFormat(name, val, isPast) {
  6249. const formatter = messages[name];
  6250. if (typeof formatter === "function")
  6251. return formatter(val, isPast);
  6252. return formatter.replace("{0}", val.toString());
  6253. }
  6254. if (absDiff < 6e4 && !showSecond)
  6255. return messages.justNow;
  6256. if (typeof max === "number" && absDiff > max)
  6257. return fullDateFormatter(new Date(from));
  6258. if (typeof max === "string") {
  6259. const unitMax = (_a = units.find((i) => i.name === max)) == null ? void 0 : _a.max;
  6260. if (unitMax && absDiff > unitMax)
  6261. return fullDateFormatter(new Date(from));
  6262. }
  6263. for (const [idx, unit] of units.entries()) {
  6264. const val = getValue(diff, unit);
  6265. if (val <= 0 && units[idx - 1])
  6266. return format(diff, units[idx - 1]);
  6267. if (absDiff < unit.max)
  6268. return format(diff, unit);
  6269. }
  6270. return messages.invalid;
  6271. }
  6272. function useTimeoutPoll(fn, interval, timeoutPollOptions) {
  6273. const { start } = shared.useTimeoutFn(loop, interval, { immediate: false });
  6274. const isActive = vue.ref(false);
  6275. async function loop() {
  6276. if (!isActive.value)
  6277. return;
  6278. await fn();
  6279. start();
  6280. }
  6281. function resume() {
  6282. if (!isActive.value) {
  6283. isActive.value = true;
  6284. loop();
  6285. }
  6286. }
  6287. function pause() {
  6288. isActive.value = false;
  6289. }
  6290. if (timeoutPollOptions == null ? void 0 : timeoutPollOptions.immediate)
  6291. resume();
  6292. shared.tryOnScopeDispose(pause);
  6293. return {
  6294. isActive,
  6295. pause,
  6296. resume
  6297. };
  6298. }
  6299. function useTimestamp(options = {}) {
  6300. const {
  6301. controls: exposeControls = false,
  6302. offset = 0,
  6303. immediate = true,
  6304. interval = "requestAnimationFrame",
  6305. callback
  6306. } = options;
  6307. const ts = vue.ref(shared.timestamp() + offset);
  6308. const update = () => ts.value = shared.timestamp() + offset;
  6309. const cb = callback ? () => {
  6310. update();
  6311. callback(ts.value);
  6312. } : update;
  6313. const controls = interval === "requestAnimationFrame" ? useRafFn(cb, { immediate }) : shared.useIntervalFn(cb, interval, { immediate });
  6314. if (exposeControls) {
  6315. return {
  6316. timestamp: ts,
  6317. ...controls
  6318. };
  6319. } else {
  6320. return ts;
  6321. }
  6322. }
  6323. function useTitle(newTitle = null, options = {}) {
  6324. var _a, _b, _c;
  6325. const {
  6326. document = defaultDocument,
  6327. restoreOnUnmount = (t) => t
  6328. } = options;
  6329. const originalTitle = (_a = document == null ? void 0 : document.title) != null ? _a : "";
  6330. const title = shared.toRef((_b = newTitle != null ? newTitle : document == null ? void 0 : document.title) != null ? _b : null);
  6331. const isReadonly = newTitle && typeof newTitle === "function";
  6332. function format(t) {
  6333. if (!("titleTemplate" in options))
  6334. return t;
  6335. const template = options.titleTemplate || "%s";
  6336. return typeof template === "function" ? template(t) : shared.toValue(template).replace(/%s/g, t);
  6337. }
  6338. vue.watch(
  6339. title,
  6340. (t, o) => {
  6341. if (t !== o && document)
  6342. document.title = format(typeof t === "string" ? t : "");
  6343. },
  6344. { immediate: true }
  6345. );
  6346. if (options.observe && !options.titleTemplate && document && !isReadonly) {
  6347. useMutationObserver(
  6348. (_c = document.head) == null ? void 0 : _c.querySelector("title"),
  6349. () => {
  6350. if (document && document.title !== title.value)
  6351. title.value = format(document.title);
  6352. },
  6353. { childList: true }
  6354. );
  6355. }
  6356. shared.tryOnBeforeUnmount(() => {
  6357. if (restoreOnUnmount) {
  6358. const restoredTitle = restoreOnUnmount(originalTitle, title.value || "");
  6359. if (restoredTitle != null && document)
  6360. document.title = restoredTitle;
  6361. }
  6362. });
  6363. return title;
  6364. }
  6365. const _TransitionPresets = {
  6366. easeInSine: [0.12, 0, 0.39, 0],
  6367. easeOutSine: [0.61, 1, 0.88, 1],
  6368. easeInOutSine: [0.37, 0, 0.63, 1],
  6369. easeInQuad: [0.11, 0, 0.5, 0],
  6370. easeOutQuad: [0.5, 1, 0.89, 1],
  6371. easeInOutQuad: [0.45, 0, 0.55, 1],
  6372. easeInCubic: [0.32, 0, 0.67, 0],
  6373. easeOutCubic: [0.33, 1, 0.68, 1],
  6374. easeInOutCubic: [0.65, 0, 0.35, 1],
  6375. easeInQuart: [0.5, 0, 0.75, 0],
  6376. easeOutQuart: [0.25, 1, 0.5, 1],
  6377. easeInOutQuart: [0.76, 0, 0.24, 1],
  6378. easeInQuint: [0.64, 0, 0.78, 0],
  6379. easeOutQuint: [0.22, 1, 0.36, 1],
  6380. easeInOutQuint: [0.83, 0, 0.17, 1],
  6381. easeInExpo: [0.7, 0, 0.84, 0],
  6382. easeOutExpo: [0.16, 1, 0.3, 1],
  6383. easeInOutExpo: [0.87, 0, 0.13, 1],
  6384. easeInCirc: [0.55, 0, 1, 0.45],
  6385. easeOutCirc: [0, 0.55, 0.45, 1],
  6386. easeInOutCirc: [0.85, 0, 0.15, 1],
  6387. easeInBack: [0.36, 0, 0.66, -0.56],
  6388. easeOutBack: [0.34, 1.56, 0.64, 1],
  6389. easeInOutBack: [0.68, -0.6, 0.32, 1.6]
  6390. };
  6391. const TransitionPresets = /* @__PURE__ */ Object.assign({}, { linear: shared.identity }, _TransitionPresets);
  6392. function createEasingFunction([p0, p1, p2, p3]) {
  6393. const a = (a1, a2) => 1 - 3 * a2 + 3 * a1;
  6394. const b = (a1, a2) => 3 * a2 - 6 * a1;
  6395. const c = (a1) => 3 * a1;
  6396. const calcBezier = (t, a1, a2) => ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t;
  6397. const getSlope = (t, a1, a2) => 3 * a(a1, a2) * t * t + 2 * b(a1, a2) * t + c(a1);
  6398. const getTforX = (x) => {
  6399. let aGuessT = x;
  6400. for (let i = 0; i < 4; ++i) {
  6401. const currentSlope = getSlope(aGuessT, p0, p2);
  6402. if (currentSlope === 0)
  6403. return aGuessT;
  6404. const currentX = calcBezier(aGuessT, p0, p2) - x;
  6405. aGuessT -= currentX / currentSlope;
  6406. }
  6407. return aGuessT;
  6408. };
  6409. return (x) => p0 === p1 && p2 === p3 ? x : calcBezier(getTforX(x), p1, p3);
  6410. }
  6411. function lerp(a, b, alpha) {
  6412. return a + alpha * (b - a);
  6413. }
  6414. function toVec(t) {
  6415. return (typeof t === "number" ? [t] : t) || [];
  6416. }
  6417. function executeTransition(source, from, to, options = {}) {
  6418. var _a, _b;
  6419. const fromVal = shared.toValue(from);
  6420. const toVal = shared.toValue(to);
  6421. const v1 = toVec(fromVal);
  6422. const v2 = toVec(toVal);
  6423. const duration = (_a = shared.toValue(options.duration)) != null ? _a : 1e3;
  6424. const startedAt = Date.now();
  6425. const endAt = Date.now() + duration;
  6426. const trans = typeof options.transition === "function" ? options.transition : (_b = shared.toValue(options.transition)) != null ? _b : shared.identity;
  6427. const ease = typeof trans === "function" ? trans : createEasingFunction(trans);
  6428. return new Promise((resolve) => {
  6429. source.value = fromVal;
  6430. const tick = () => {
  6431. var _a2;
  6432. if ((_a2 = options.abort) == null ? void 0 : _a2.call(options)) {
  6433. resolve();
  6434. return;
  6435. }
  6436. const now = Date.now();
  6437. const alpha = ease((now - startedAt) / duration);
  6438. const arr = toVec(source.value).map((n, i) => lerp(v1[i], v2[i], alpha));
  6439. if (Array.isArray(source.value))
  6440. source.value = arr.map((n, i) => {
  6441. var _a3, _b2;
  6442. return lerp((_a3 = v1[i]) != null ? _a3 : 0, (_b2 = v2[i]) != null ? _b2 : 0, alpha);
  6443. });
  6444. else if (typeof source.value === "number")
  6445. source.value = arr[0];
  6446. if (now < endAt) {
  6447. requestAnimationFrame(tick);
  6448. } else {
  6449. source.value = toVal;
  6450. resolve();
  6451. }
  6452. };
  6453. tick();
  6454. });
  6455. }
  6456. function useTransition(source, options = {}) {
  6457. let currentId = 0;
  6458. const sourceVal = () => {
  6459. const v = shared.toValue(source);
  6460. return typeof v === "number" ? v : v.map(shared.toValue);
  6461. };
  6462. const outputRef = vue.ref(sourceVal());
  6463. vue.watch(sourceVal, async (to) => {
  6464. var _a, _b;
  6465. if (shared.toValue(options.disabled))
  6466. return;
  6467. const id = ++currentId;
  6468. if (options.delay)
  6469. await shared.promiseTimeout(shared.toValue(options.delay));
  6470. if (id !== currentId)
  6471. return;
  6472. const toVal = Array.isArray(to) ? to.map(shared.toValue) : shared.toValue(to);
  6473. (_a = options.onStarted) == null ? void 0 : _a.call(options);
  6474. await executeTransition(outputRef, outputRef.value, toVal, {
  6475. ...options,
  6476. abort: () => {
  6477. var _a2;
  6478. return id !== currentId || ((_a2 = options.abort) == null ? void 0 : _a2.call(options));
  6479. }
  6480. });
  6481. (_b = options.onFinished) == null ? void 0 : _b.call(options);
  6482. }, { deep: true });
  6483. vue.watch(() => shared.toValue(options.disabled), (disabled) => {
  6484. if (disabled) {
  6485. currentId++;
  6486. outputRef.value = sourceVal();
  6487. }
  6488. });
  6489. shared.tryOnScopeDispose(() => {
  6490. currentId++;
  6491. });
  6492. return vue.computed(() => shared.toValue(options.disabled) ? sourceVal() : outputRef.value);
  6493. }
  6494. function useUrlSearchParams(mode = "history", options = {}) {
  6495. const {
  6496. initialValue = {},
  6497. removeNullishValues = true,
  6498. removeFalsyValues = false,
  6499. write: enableWrite = true,
  6500. window = defaultWindow
  6501. } = options;
  6502. if (!window)
  6503. return vue.reactive(initialValue);
  6504. const state = vue.reactive({});
  6505. function getRawParams() {
  6506. if (mode === "history") {
  6507. return window.location.search || "";
  6508. } else if (mode === "hash") {
  6509. const hash = window.location.hash || "";
  6510. const index = hash.indexOf("?");
  6511. return index > 0 ? hash.slice(index) : "";
  6512. } else {
  6513. return (window.location.hash || "").replace(/^#/, "");
  6514. }
  6515. }
  6516. function constructQuery(params) {
  6517. const stringified = params.toString();
  6518. if (mode === "history")
  6519. return `${stringified ? `?${stringified}` : ""}${window.location.hash || ""}`;
  6520. if (mode === "hash-params")
  6521. return `${window.location.search || ""}${stringified ? `#${stringified}` : ""}`;
  6522. const hash = window.location.hash || "#";
  6523. const index = hash.indexOf("?");
  6524. if (index > 0)
  6525. return `${window.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
  6526. return `${window.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
  6527. }
  6528. function read() {
  6529. return new URLSearchParams(getRawParams());
  6530. }
  6531. function updateState(params) {
  6532. const unusedKeys = new Set(Object.keys(state));
  6533. for (const key of params.keys()) {
  6534. const paramsForKey = params.getAll(key);
  6535. state[key] = paramsForKey.length > 1 ? paramsForKey : params.get(key) || "";
  6536. unusedKeys.delete(key);
  6537. }
  6538. Array.from(unusedKeys).forEach((key) => delete state[key]);
  6539. }
  6540. const { pause, resume } = shared.pausableWatch(
  6541. state,
  6542. () => {
  6543. const params = new URLSearchParams("");
  6544. Object.keys(state).forEach((key) => {
  6545. const mapEntry = state[key];
  6546. if (Array.isArray(mapEntry))
  6547. mapEntry.forEach((value) => params.append(key, value));
  6548. else if (removeNullishValues && mapEntry == null)
  6549. params.delete(key);
  6550. else if (removeFalsyValues && !mapEntry)
  6551. params.delete(key);
  6552. else
  6553. params.set(key, mapEntry);
  6554. });
  6555. write(params);
  6556. },
  6557. { deep: true }
  6558. );
  6559. function write(params, shouldUpdate) {
  6560. pause();
  6561. if (shouldUpdate)
  6562. updateState(params);
  6563. window.history.replaceState(
  6564. window.history.state,
  6565. window.document.title,
  6566. window.location.pathname + constructQuery(params)
  6567. );
  6568. resume();
  6569. }
  6570. function onChanged() {
  6571. if (!enableWrite)
  6572. return;
  6573. write(read(), true);
  6574. }
  6575. useEventListener(window, "popstate", onChanged, false);
  6576. if (mode !== "history")
  6577. useEventListener(window, "hashchange", onChanged, false);
  6578. const initial = read();
  6579. if (initial.keys().next().value)
  6580. updateState(initial);
  6581. else
  6582. Object.assign(state, initialValue);
  6583. return state;
  6584. }
  6585. function useUserMedia(options = {}) {
  6586. var _a, _b;
  6587. const enabled = vue.ref((_a = options.enabled) != null ? _a : false);
  6588. const autoSwitch = vue.ref((_b = options.autoSwitch) != null ? _b : true);
  6589. const constraints = vue.ref(options.constraints);
  6590. const { navigator = defaultNavigator } = options;
  6591. const isSupported = useSupported(() => {
  6592. var _a2;
  6593. return (_a2 = navigator == null ? void 0 : navigator.mediaDevices) == null ? void 0 : _a2.getUserMedia;
  6594. });
  6595. const stream = vue.shallowRef();
  6596. function getDeviceOptions(type) {
  6597. switch (type) {
  6598. case "video": {
  6599. if (constraints.value)
  6600. return constraints.value.video || false;
  6601. break;
  6602. }
  6603. case "audio": {
  6604. if (constraints.value)
  6605. return constraints.value.audio || false;
  6606. break;
  6607. }
  6608. }
  6609. }
  6610. async function _start() {
  6611. if (!isSupported.value || stream.value)
  6612. return;
  6613. stream.value = await navigator.mediaDevices.getUserMedia({
  6614. video: getDeviceOptions("video"),
  6615. audio: getDeviceOptions("audio")
  6616. });
  6617. return stream.value;
  6618. }
  6619. function _stop() {
  6620. var _a2;
  6621. (_a2 = stream.value) == null ? void 0 : _a2.getTracks().forEach((t) => t.stop());
  6622. stream.value = void 0;
  6623. }
  6624. function stop() {
  6625. _stop();
  6626. enabled.value = false;
  6627. }
  6628. async function start() {
  6629. await _start();
  6630. if (stream.value)
  6631. enabled.value = true;
  6632. return stream.value;
  6633. }
  6634. async function restart() {
  6635. _stop();
  6636. return await start();
  6637. }
  6638. vue.watch(
  6639. enabled,
  6640. (v) => {
  6641. if (v)
  6642. _start();
  6643. else _stop();
  6644. },
  6645. { immediate: true }
  6646. );
  6647. vue.watch(
  6648. constraints,
  6649. () => {
  6650. if (autoSwitch.value && stream.value)
  6651. restart();
  6652. },
  6653. { immediate: true }
  6654. );
  6655. shared.tryOnScopeDispose(() => {
  6656. stop();
  6657. });
  6658. return {
  6659. isSupported,
  6660. stream,
  6661. start,
  6662. stop,
  6663. restart,
  6664. constraints,
  6665. enabled,
  6666. autoSwitch
  6667. };
  6668. }
  6669. function useVModel(props, key, emit, options = {}) {
  6670. var _a, _b, _c;
  6671. const {
  6672. clone = false,
  6673. passive = false,
  6674. eventName,
  6675. deep = false,
  6676. defaultValue,
  6677. shouldEmit
  6678. } = options;
  6679. const vm = vue.getCurrentInstance();
  6680. const _emit = emit || (vm == null ? void 0 : vm.emit) || ((_a = vm == null ? void 0 : vm.$emit) == null ? void 0 : _a.bind(vm)) || ((_c = (_b = vm == null ? void 0 : vm.proxy) == null ? void 0 : _b.$emit) == null ? void 0 : _c.bind(vm == null ? void 0 : vm.proxy));
  6681. let event = eventName;
  6682. if (!key) {
  6683. key = "modelValue";
  6684. }
  6685. event = event || `update:${key.toString()}`;
  6686. const cloneFn = (val) => !clone ? val : typeof clone === "function" ? clone(val) : cloneFnJSON(val);
  6687. const getValue = () => shared.isDef(props[key]) ? cloneFn(props[key]) : defaultValue;
  6688. const triggerEmit = (value) => {
  6689. if (shouldEmit) {
  6690. if (shouldEmit(value))
  6691. _emit(event, value);
  6692. } else {
  6693. _emit(event, value);
  6694. }
  6695. };
  6696. if (passive) {
  6697. const initialValue = getValue();
  6698. const proxy = vue.ref(initialValue);
  6699. let isUpdating = false;
  6700. vue.watch(
  6701. () => props[key],
  6702. (v) => {
  6703. if (!isUpdating) {
  6704. isUpdating = true;
  6705. proxy.value = cloneFn(v);
  6706. vue.nextTick(() => isUpdating = false);
  6707. }
  6708. }
  6709. );
  6710. vue.watch(
  6711. proxy,
  6712. (v) => {
  6713. if (!isUpdating && (v !== props[key] || deep))
  6714. triggerEmit(v);
  6715. },
  6716. { deep }
  6717. );
  6718. return proxy;
  6719. } else {
  6720. return vue.computed({
  6721. get() {
  6722. return getValue();
  6723. },
  6724. set(value) {
  6725. triggerEmit(value);
  6726. }
  6727. });
  6728. }
  6729. }
  6730. function useVModels(props, emit, options = {}) {
  6731. const ret = {};
  6732. for (const key in props) {
  6733. ret[key] = useVModel(
  6734. props,
  6735. key,
  6736. emit,
  6737. options
  6738. );
  6739. }
  6740. return ret;
  6741. }
  6742. function useVibrate(options) {
  6743. const {
  6744. pattern = [],
  6745. interval = 0,
  6746. navigator = defaultNavigator
  6747. } = options || {};
  6748. const isSupported = useSupported(() => typeof navigator !== "undefined" && "vibrate" in navigator);
  6749. const patternRef = shared.toRef(pattern);
  6750. let intervalControls;
  6751. const vibrate = (pattern2 = patternRef.value) => {
  6752. if (isSupported.value)
  6753. navigator.vibrate(pattern2);
  6754. };
  6755. const stop = () => {
  6756. if (isSupported.value)
  6757. navigator.vibrate(0);
  6758. intervalControls == null ? void 0 : intervalControls.pause();
  6759. };
  6760. if (interval > 0) {
  6761. intervalControls = shared.useIntervalFn(
  6762. vibrate,
  6763. interval,
  6764. {
  6765. immediate: false,
  6766. immediateCallback: false
  6767. }
  6768. );
  6769. }
  6770. return {
  6771. isSupported,
  6772. pattern,
  6773. intervalControls,
  6774. vibrate,
  6775. stop
  6776. };
  6777. }
  6778. function useVirtualList(list, options) {
  6779. const { containerStyle, wrapperProps, scrollTo, calculateRange, currentList, containerRef } = "itemHeight" in options ? useVerticalVirtualList(options, list) : useHorizontalVirtualList(options, list);
  6780. return {
  6781. list: currentList,
  6782. scrollTo,
  6783. containerProps: {
  6784. ref: containerRef,
  6785. onScroll: () => {
  6786. calculateRange();
  6787. },
  6788. style: containerStyle
  6789. },
  6790. wrapperProps
  6791. };
  6792. }
  6793. function useVirtualListResources(list) {
  6794. const containerRef = vue.ref(null);
  6795. const size = useElementSize(containerRef);
  6796. const currentList = vue.ref([]);
  6797. const source = vue.shallowRef(list);
  6798. const state = vue.ref({ start: 0, end: 10 });
  6799. return { state, source, currentList, size, containerRef };
  6800. }
  6801. function createGetViewCapacity(state, source, itemSize) {
  6802. return (containerSize) => {
  6803. if (typeof itemSize === "number")
  6804. return Math.ceil(containerSize / itemSize);
  6805. const { start = 0 } = state.value;
  6806. let sum = 0;
  6807. let capacity = 0;
  6808. for (let i = start; i < source.value.length; i++) {
  6809. const size = itemSize(i);
  6810. sum += size;
  6811. capacity = i;
  6812. if (sum > containerSize)
  6813. break;
  6814. }
  6815. return capacity - start;
  6816. };
  6817. }
  6818. function createGetOffset(source, itemSize) {
  6819. return (scrollDirection) => {
  6820. if (typeof itemSize === "number")
  6821. return Math.floor(scrollDirection / itemSize) + 1;
  6822. let sum = 0;
  6823. let offset = 0;
  6824. for (let i = 0; i < source.value.length; i++) {
  6825. const size = itemSize(i);
  6826. sum += size;
  6827. if (sum >= scrollDirection) {
  6828. offset = i;
  6829. break;
  6830. }
  6831. }
  6832. return offset + 1;
  6833. };
  6834. }
  6835. function createCalculateRange(type, overscan, getOffset, getViewCapacity, { containerRef, state, currentList, source }) {
  6836. return () => {
  6837. const element = containerRef.value;
  6838. if (element) {
  6839. const offset = getOffset(type === "vertical" ? element.scrollTop : element.scrollLeft);
  6840. const viewCapacity = getViewCapacity(type === "vertical" ? element.clientHeight : element.clientWidth);
  6841. const from = offset - overscan;
  6842. const to = offset + viewCapacity + overscan;
  6843. state.value = {
  6844. start: from < 0 ? 0 : from,
  6845. end: to > source.value.length ? source.value.length : to
  6846. };
  6847. currentList.value = source.value.slice(state.value.start, state.value.end).map((ele, index) => ({
  6848. data: ele,
  6849. index: index + state.value.start
  6850. }));
  6851. }
  6852. };
  6853. }
  6854. function createGetDistance(itemSize, source) {
  6855. return (index) => {
  6856. if (typeof itemSize === "number") {
  6857. const size2 = index * itemSize;
  6858. return size2;
  6859. }
  6860. const size = source.value.slice(0, index).reduce((sum, _, i) => sum + itemSize(i), 0);
  6861. return size;
  6862. };
  6863. }
  6864. function useWatchForSizes(size, list, containerRef, calculateRange) {
  6865. vue.watch([size.width, size.height, list, containerRef], () => {
  6866. calculateRange();
  6867. });
  6868. }
  6869. function createComputedTotalSize(itemSize, source) {
  6870. return vue.computed(() => {
  6871. if (typeof itemSize === "number")
  6872. return source.value.length * itemSize;
  6873. return source.value.reduce((sum, _, index) => sum + itemSize(index), 0);
  6874. });
  6875. }
  6876. const scrollToDictionaryForElementScrollKey = {
  6877. horizontal: "scrollLeft",
  6878. vertical: "scrollTop"
  6879. };
  6880. function createScrollTo(type, calculateRange, getDistance, containerRef) {
  6881. return (index) => {
  6882. if (containerRef.value) {
  6883. containerRef.value[scrollToDictionaryForElementScrollKey[type]] = getDistance(index);
  6884. calculateRange();
  6885. }
  6886. };
  6887. }
  6888. function useHorizontalVirtualList(options, list) {
  6889. const resources = useVirtualListResources(list);
  6890. const { state, source, currentList, size, containerRef } = resources;
  6891. const containerStyle = { overflowX: "auto" };
  6892. const { itemWidth, overscan = 5 } = options;
  6893. const getViewCapacity = createGetViewCapacity(state, source, itemWidth);
  6894. const getOffset = createGetOffset(source, itemWidth);
  6895. const calculateRange = createCalculateRange("horizontal", overscan, getOffset, getViewCapacity, resources);
  6896. const getDistanceLeft = createGetDistance(itemWidth, source);
  6897. const offsetLeft = vue.computed(() => getDistanceLeft(state.value.start));
  6898. const totalWidth = createComputedTotalSize(itemWidth, source);
  6899. useWatchForSizes(size, list, containerRef, calculateRange);
  6900. const scrollTo = createScrollTo("horizontal", calculateRange, getDistanceLeft, containerRef);
  6901. const wrapperProps = vue.computed(() => {
  6902. return {
  6903. style: {
  6904. height: "100%",
  6905. width: `${totalWidth.value - offsetLeft.value}px`,
  6906. marginLeft: `${offsetLeft.value}px`,
  6907. display: "flex"
  6908. }
  6909. };
  6910. });
  6911. return {
  6912. scrollTo,
  6913. calculateRange,
  6914. wrapperProps,
  6915. containerStyle,
  6916. currentList,
  6917. containerRef
  6918. };
  6919. }
  6920. function useVerticalVirtualList(options, list) {
  6921. const resources = useVirtualListResources(list);
  6922. const { state, source, currentList, size, containerRef } = resources;
  6923. const containerStyle = { overflowY: "auto" };
  6924. const { itemHeight, overscan = 5 } = options;
  6925. const getViewCapacity = createGetViewCapacity(state, source, itemHeight);
  6926. const getOffset = createGetOffset(source, itemHeight);
  6927. const calculateRange = createCalculateRange("vertical", overscan, getOffset, getViewCapacity, resources);
  6928. const getDistanceTop = createGetDistance(itemHeight, source);
  6929. const offsetTop = vue.computed(() => getDistanceTop(state.value.start));
  6930. const totalHeight = createComputedTotalSize(itemHeight, source);
  6931. useWatchForSizes(size, list, containerRef, calculateRange);
  6932. const scrollTo = createScrollTo("vertical", calculateRange, getDistanceTop, containerRef);
  6933. const wrapperProps = vue.computed(() => {
  6934. return {
  6935. style: {
  6936. width: "100%",
  6937. height: `${totalHeight.value - offsetTop.value}px`,
  6938. marginTop: `${offsetTop.value}px`
  6939. }
  6940. };
  6941. });
  6942. return {
  6943. calculateRange,
  6944. scrollTo,
  6945. containerStyle,
  6946. wrapperProps,
  6947. currentList,
  6948. containerRef
  6949. };
  6950. }
  6951. function useWakeLock(options = {}) {
  6952. const {
  6953. navigator = defaultNavigator,
  6954. document = defaultDocument
  6955. } = options;
  6956. const requestedType = vue.ref(false);
  6957. const sentinel = vue.shallowRef(null);
  6958. const documentVisibility = useDocumentVisibility({ document });
  6959. const isSupported = useSupported(() => navigator && "wakeLock" in navigator);
  6960. const isActive = vue.computed(() => !!sentinel.value && documentVisibility.value === "visible");
  6961. if (isSupported.value) {
  6962. useEventListener(sentinel, "release", () => {
  6963. var _a, _b;
  6964. requestedType.value = (_b = (_a = sentinel.value) == null ? void 0 : _a.type) != null ? _b : false;
  6965. });
  6966. shared.whenever(
  6967. () => documentVisibility.value === "visible" && (document == null ? void 0 : document.visibilityState) === "visible" && requestedType.value,
  6968. (type) => {
  6969. requestedType.value = false;
  6970. forceRequest(type);
  6971. }
  6972. );
  6973. }
  6974. async function forceRequest(type) {
  6975. var _a;
  6976. await ((_a = sentinel.value) == null ? void 0 : _a.release());
  6977. sentinel.value = isSupported.value ? await navigator.wakeLock.request(type) : null;
  6978. }
  6979. async function request(type) {
  6980. if (documentVisibility.value === "visible")
  6981. await forceRequest(type);
  6982. else
  6983. requestedType.value = type;
  6984. }
  6985. async function release() {
  6986. requestedType.value = false;
  6987. const s = sentinel.value;
  6988. sentinel.value = null;
  6989. await (s == null ? void 0 : s.release());
  6990. }
  6991. return {
  6992. sentinel,
  6993. isSupported,
  6994. isActive,
  6995. request,
  6996. forceRequest,
  6997. release
  6998. };
  6999. }
  7000. function useWebNotification(options = {}) {
  7001. const {
  7002. window = defaultWindow,
  7003. requestPermissions: _requestForPermissions = true
  7004. } = options;
  7005. const defaultWebNotificationOptions = options;
  7006. const isSupported = useSupported(() => {
  7007. if (!window || !("Notification" in window))
  7008. return false;
  7009. try {
  7010. new Notification("");
  7011. } catch (e) {
  7012. return false;
  7013. }
  7014. return true;
  7015. });
  7016. const permissionGranted = vue.ref(isSupported.value && "permission" in Notification && Notification.permission === "granted");
  7017. const notification = vue.ref(null);
  7018. const ensurePermissions = async () => {
  7019. if (!isSupported.value)
  7020. return;
  7021. if (!permissionGranted.value && Notification.permission !== "denied") {
  7022. const result = await Notification.requestPermission();
  7023. if (result === "granted")
  7024. permissionGranted.value = true;
  7025. }
  7026. return permissionGranted.value;
  7027. };
  7028. const { on: onClick, trigger: clickTrigger } = shared.createEventHook();
  7029. const { on: onShow, trigger: showTrigger } = shared.createEventHook();
  7030. const { on: onError, trigger: errorTrigger } = shared.createEventHook();
  7031. const { on: onClose, trigger: closeTrigger } = shared.createEventHook();
  7032. const show = async (overrides) => {
  7033. if (!isSupported.value || !permissionGranted.value)
  7034. return;
  7035. const options2 = Object.assign({}, defaultWebNotificationOptions, overrides);
  7036. notification.value = new Notification(options2.title || "", options2);
  7037. notification.value.onclick = clickTrigger;
  7038. notification.value.onshow = showTrigger;
  7039. notification.value.onerror = errorTrigger;
  7040. notification.value.onclose = closeTrigger;
  7041. return notification.value;
  7042. };
  7043. const close = () => {
  7044. if (notification.value)
  7045. notification.value.close();
  7046. notification.value = null;
  7047. };
  7048. if (_requestForPermissions)
  7049. shared.tryOnMounted(ensurePermissions);
  7050. shared.tryOnScopeDispose(close);
  7051. if (isSupported.value && window) {
  7052. const document = window.document;
  7053. useEventListener(document, "visibilitychange", (e) => {
  7054. e.preventDefault();
  7055. if (document.visibilityState === "visible") {
  7056. close();
  7057. }
  7058. });
  7059. }
  7060. return {
  7061. isSupported,
  7062. notification,
  7063. ensurePermissions,
  7064. permissionGranted,
  7065. show,
  7066. close,
  7067. onClick,
  7068. onShow,
  7069. onError,
  7070. onClose
  7071. };
  7072. }
  7073. const DEFAULT_PING_MESSAGE = "ping";
  7074. function resolveNestedOptions(options) {
  7075. if (options === true)
  7076. return {};
  7077. return options;
  7078. }
  7079. function useWebSocket(url, options = {}) {
  7080. const {
  7081. onConnected,
  7082. onDisconnected,
  7083. onError,
  7084. onMessage,
  7085. immediate = true,
  7086. autoClose = true,
  7087. protocols = []
  7088. } = options;
  7089. const data = vue.ref(null);
  7090. const status = vue.ref("CLOSED");
  7091. const wsRef = vue.ref();
  7092. const urlRef = shared.toRef(url);
  7093. let heartbeatPause;
  7094. let heartbeatResume;
  7095. let explicitlyClosed = false;
  7096. let retried = 0;
  7097. let bufferedData = [];
  7098. let pongTimeoutWait;
  7099. const _sendBuffer = () => {
  7100. if (bufferedData.length && wsRef.value && status.value === "OPEN") {
  7101. for (const buffer of bufferedData)
  7102. wsRef.value.send(buffer);
  7103. bufferedData = [];
  7104. }
  7105. };
  7106. const resetHeartbeat = () => {
  7107. clearTimeout(pongTimeoutWait);
  7108. pongTimeoutWait = void 0;
  7109. };
  7110. const close = (code = 1e3, reason) => {
  7111. if (!shared.isClient || !wsRef.value)
  7112. return;
  7113. explicitlyClosed = true;
  7114. resetHeartbeat();
  7115. heartbeatPause == null ? void 0 : heartbeatPause();
  7116. wsRef.value.close(code, reason);
  7117. wsRef.value = void 0;
  7118. };
  7119. const send = (data2, useBuffer = true) => {
  7120. if (!wsRef.value || status.value !== "OPEN") {
  7121. if (useBuffer)
  7122. bufferedData.push(data2);
  7123. return false;
  7124. }
  7125. _sendBuffer();
  7126. wsRef.value.send(data2);
  7127. return true;
  7128. };
  7129. const _init = () => {
  7130. if (explicitlyClosed || typeof urlRef.value === "undefined")
  7131. return;
  7132. const ws = new WebSocket(urlRef.value, protocols);
  7133. wsRef.value = ws;
  7134. status.value = "CONNECTING";
  7135. ws.onopen = () => {
  7136. status.value = "OPEN";
  7137. retried = 0;
  7138. onConnected == null ? void 0 : onConnected(ws);
  7139. heartbeatResume == null ? void 0 : heartbeatResume();
  7140. _sendBuffer();
  7141. };
  7142. ws.onclose = (ev) => {
  7143. status.value = "CLOSED";
  7144. onDisconnected == null ? void 0 : onDisconnected(ws, ev);
  7145. if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
  7146. const {
  7147. retries = -1,
  7148. delay = 1e3,
  7149. onFailed
  7150. } = resolveNestedOptions(options.autoReconnect);
  7151. if (typeof retries === "number" && (retries < 0 || retried < retries)) {
  7152. retried += 1;
  7153. setTimeout(_init, delay);
  7154. } else if (typeof retries === "function" && retries()) {
  7155. setTimeout(_init, delay);
  7156. } else {
  7157. onFailed == null ? void 0 : onFailed();
  7158. }
  7159. }
  7160. };
  7161. ws.onerror = (e) => {
  7162. onError == null ? void 0 : onError(ws, e);
  7163. };
  7164. ws.onmessage = (e) => {
  7165. if (options.heartbeat) {
  7166. resetHeartbeat();
  7167. const {
  7168. message = DEFAULT_PING_MESSAGE,
  7169. responseMessage = message
  7170. } = resolveNestedOptions(options.heartbeat);
  7171. if (e.data === responseMessage)
  7172. return;
  7173. }
  7174. data.value = e.data;
  7175. onMessage == null ? void 0 : onMessage(ws, e);
  7176. };
  7177. };
  7178. if (options.heartbeat) {
  7179. const {
  7180. message = DEFAULT_PING_MESSAGE,
  7181. interval = 1e3,
  7182. pongTimeout = 1e3
  7183. } = resolveNestedOptions(options.heartbeat);
  7184. const { pause, resume } = shared.useIntervalFn(
  7185. () => {
  7186. send(message, false);
  7187. if (pongTimeoutWait != null)
  7188. return;
  7189. pongTimeoutWait = setTimeout(() => {
  7190. close();
  7191. explicitlyClosed = false;
  7192. }, pongTimeout);
  7193. },
  7194. interval,
  7195. { immediate: false }
  7196. );
  7197. heartbeatPause = pause;
  7198. heartbeatResume = resume;
  7199. }
  7200. if (autoClose) {
  7201. if (shared.isClient)
  7202. useEventListener("beforeunload", () => close());
  7203. shared.tryOnScopeDispose(close);
  7204. }
  7205. const open = () => {
  7206. if (!shared.isClient && !shared.isWorker)
  7207. return;
  7208. close();
  7209. explicitlyClosed = false;
  7210. retried = 0;
  7211. _init();
  7212. };
  7213. if (immediate)
  7214. open();
  7215. vue.watch(urlRef, open);
  7216. return {
  7217. data,
  7218. status,
  7219. close,
  7220. send,
  7221. open,
  7222. ws: wsRef
  7223. };
  7224. }
  7225. function useWebWorker(arg0, workerOptions, options) {
  7226. const {
  7227. window = defaultWindow
  7228. } = options != null ? options : {};
  7229. const data = vue.ref(null);
  7230. const worker = vue.shallowRef();
  7231. const post = (...args) => {
  7232. if (!worker.value)
  7233. return;
  7234. worker.value.postMessage(...args);
  7235. };
  7236. const terminate = function terminate2() {
  7237. if (!worker.value)
  7238. return;
  7239. worker.value.terminate();
  7240. };
  7241. if (window) {
  7242. if (typeof arg0 === "string")
  7243. worker.value = new Worker(arg0, workerOptions);
  7244. else if (typeof arg0 === "function")
  7245. worker.value = arg0();
  7246. else
  7247. worker.value = arg0;
  7248. worker.value.onmessage = (e) => {
  7249. data.value = e.data;
  7250. };
  7251. shared.tryOnScopeDispose(() => {
  7252. if (worker.value)
  7253. worker.value.terminate();
  7254. });
  7255. }
  7256. return {
  7257. data,
  7258. post,
  7259. terminate,
  7260. worker
  7261. };
  7262. }
  7263. function depsParser(deps, localDeps) {
  7264. if (deps.length === 0 && localDeps.length === 0)
  7265. return "";
  7266. const depsString = deps.map((dep) => `'${dep}'`).toString();
  7267. const depsFunctionString = localDeps.filter((dep) => typeof dep === "function").map((fn) => {
  7268. const str = fn.toString();
  7269. if (str.trim().startsWith("function")) {
  7270. return str;
  7271. } else {
  7272. const name = fn.name;
  7273. return `const ${name} = ${str}`;
  7274. }
  7275. }).join(";");
  7276. const importString = `importScripts(${depsString});`;
  7277. return `${depsString.trim() === "" ? "" : importString} ${depsFunctionString}`;
  7278. }
  7279. function jobRunner(userFunc) {
  7280. return (e) => {
  7281. const userFuncArgs = e.data[0];
  7282. return Promise.resolve(userFunc.apply(void 0, userFuncArgs)).then((result) => {
  7283. postMessage(["SUCCESS", result]);
  7284. }).catch((error) => {
  7285. postMessage(["ERROR", error]);
  7286. });
  7287. };
  7288. }
  7289. function createWorkerBlobUrl(fn, deps, localDeps) {
  7290. const blobCode = `${depsParser(deps, localDeps)}; onmessage=(${jobRunner})(${fn})`;
  7291. const blob = new Blob([blobCode], { type: "text/javascript" });
  7292. const url = URL.createObjectURL(blob);
  7293. return url;
  7294. }
  7295. function useWebWorkerFn(fn, options = {}) {
  7296. const {
  7297. dependencies = [],
  7298. localDependencies = [],
  7299. timeout,
  7300. window = defaultWindow
  7301. } = options;
  7302. const worker = vue.ref();
  7303. const workerStatus = vue.ref("PENDING");
  7304. const promise = vue.ref({});
  7305. const timeoutId = vue.ref();
  7306. const workerTerminate = (status = "PENDING") => {
  7307. if (worker.value && worker.value._url && window) {
  7308. worker.value.terminate();
  7309. URL.revokeObjectURL(worker.value._url);
  7310. promise.value = {};
  7311. worker.value = void 0;
  7312. window.clearTimeout(timeoutId.value);
  7313. workerStatus.value = status;
  7314. }
  7315. };
  7316. workerTerminate();
  7317. shared.tryOnScopeDispose(workerTerminate);
  7318. const generateWorker = () => {
  7319. const blobUrl = createWorkerBlobUrl(fn, dependencies, localDependencies);
  7320. const newWorker = new Worker(blobUrl);
  7321. newWorker._url = blobUrl;
  7322. newWorker.onmessage = (e) => {
  7323. const { resolve = () => {
  7324. }, reject = () => {
  7325. } } = promise.value;
  7326. const [status, result] = e.data;
  7327. switch (status) {
  7328. case "SUCCESS":
  7329. resolve(result);
  7330. workerTerminate(status);
  7331. break;
  7332. default:
  7333. reject(result);
  7334. workerTerminate("ERROR");
  7335. break;
  7336. }
  7337. };
  7338. newWorker.onerror = (e) => {
  7339. const { reject = () => {
  7340. } } = promise.value;
  7341. e.preventDefault();
  7342. reject(e);
  7343. workerTerminate("ERROR");
  7344. };
  7345. if (timeout) {
  7346. timeoutId.value = setTimeout(
  7347. () => workerTerminate("TIMEOUT_EXPIRED"),
  7348. timeout
  7349. );
  7350. }
  7351. return newWorker;
  7352. };
  7353. const callWorker = (...fnArgs) => new Promise((resolve, reject) => {
  7354. var _a;
  7355. promise.value = {
  7356. resolve,
  7357. reject
  7358. };
  7359. (_a = worker.value) == null ? void 0 : _a.postMessage([[...fnArgs]]);
  7360. workerStatus.value = "RUNNING";
  7361. });
  7362. const workerFn = (...fnArgs) => {
  7363. if (workerStatus.value === "RUNNING") {
  7364. console.error(
  7365. "[useWebWorkerFn] You can only run one instance of the worker at a time."
  7366. );
  7367. return Promise.reject();
  7368. }
  7369. worker.value = generateWorker();
  7370. return callWorker(...fnArgs);
  7371. };
  7372. return {
  7373. workerFn,
  7374. workerStatus,
  7375. workerTerminate
  7376. };
  7377. }
  7378. function useWindowFocus(options = {}) {
  7379. const { window = defaultWindow } = options;
  7380. if (!window)
  7381. return vue.ref(false);
  7382. const focused = vue.ref(window.document.hasFocus());
  7383. useEventListener(window, "blur", () => {
  7384. focused.value = false;
  7385. });
  7386. useEventListener(window, "focus", () => {
  7387. focused.value = true;
  7388. });
  7389. return focused;
  7390. }
  7391. function useWindowScroll(options = {}) {
  7392. const { window = defaultWindow, behavior = "auto" } = options;
  7393. if (!window) {
  7394. return {
  7395. x: vue.ref(0),
  7396. y: vue.ref(0)
  7397. };
  7398. }
  7399. const internalX = vue.ref(window.scrollX);
  7400. const internalY = vue.ref(window.scrollY);
  7401. const x = vue.computed({
  7402. get() {
  7403. return internalX.value;
  7404. },
  7405. set(x2) {
  7406. scrollTo({ left: x2, behavior });
  7407. }
  7408. });
  7409. const y = vue.computed({
  7410. get() {
  7411. return internalY.value;
  7412. },
  7413. set(y2) {
  7414. scrollTo({ top: y2, behavior });
  7415. }
  7416. });
  7417. useEventListener(
  7418. window,
  7419. "scroll",
  7420. () => {
  7421. internalX.value = window.scrollX;
  7422. internalY.value = window.scrollY;
  7423. },
  7424. {
  7425. capture: false,
  7426. passive: true
  7427. }
  7428. );
  7429. return { x, y };
  7430. }
  7431. function useWindowSize(options = {}) {
  7432. const {
  7433. window = defaultWindow,
  7434. initialWidth = Number.POSITIVE_INFINITY,
  7435. initialHeight = Number.POSITIVE_INFINITY,
  7436. listenOrientation = true,
  7437. includeScrollbar = true,
  7438. type = "inner"
  7439. } = options;
  7440. const width = vue.ref(initialWidth);
  7441. const height = vue.ref(initialHeight);
  7442. const update = () => {
  7443. if (window) {
  7444. if (type === "outer") {
  7445. width.value = window.outerWidth;
  7446. height.value = window.outerHeight;
  7447. } else if (includeScrollbar) {
  7448. width.value = window.innerWidth;
  7449. height.value = window.innerHeight;
  7450. } else {
  7451. width.value = window.document.documentElement.clientWidth;
  7452. height.value = window.document.documentElement.clientHeight;
  7453. }
  7454. }
  7455. };
  7456. update();
  7457. shared.tryOnMounted(update);
  7458. useEventListener("resize", update, { passive: true });
  7459. if (listenOrientation) {
  7460. const matches = useMediaQuery("(orientation: portrait)");
  7461. vue.watch(matches, () => update());
  7462. }
  7463. return { width, height };
  7464. }
  7465. exports.DefaultMagicKeysAliasMap = DefaultMagicKeysAliasMap;
  7466. exports.StorageSerializers = StorageSerializers;
  7467. exports.TransitionPresets = TransitionPresets;
  7468. exports.asyncComputed = computedAsync;
  7469. exports.breakpointsAntDesign = breakpointsAntDesign;
  7470. exports.breakpointsBootstrapV5 = breakpointsBootstrapV5;
  7471. exports.breakpointsElement = breakpointsElement;
  7472. exports.breakpointsMasterCss = breakpointsMasterCss;
  7473. exports.breakpointsPrimeFlex = breakpointsPrimeFlex;
  7474. exports.breakpointsQuasar = breakpointsQuasar;
  7475. exports.breakpointsSematic = breakpointsSematic;
  7476. exports.breakpointsTailwind = breakpointsTailwind;
  7477. exports.breakpointsVuetify = breakpointsVuetify;
  7478. exports.breakpointsVuetifyV2 = breakpointsVuetifyV2;
  7479. exports.breakpointsVuetifyV3 = breakpointsVuetifyV3;
  7480. exports.cloneFnJSON = cloneFnJSON;
  7481. exports.computedAsync = computedAsync;
  7482. exports.computedInject = computedInject;
  7483. exports.createFetch = createFetch;
  7484. exports.createReusableTemplate = createReusableTemplate;
  7485. exports.createTemplatePromise = createTemplatePromise;
  7486. exports.createUnrefFn = createUnrefFn;
  7487. exports.customStorageEventName = customStorageEventName;
  7488. exports.defaultDocument = defaultDocument;
  7489. exports.defaultLocation = defaultLocation;
  7490. exports.defaultNavigator = defaultNavigator;
  7491. exports.defaultWindow = defaultWindow;
  7492. exports.executeTransition = executeTransition;
  7493. exports.formatTimeAgo = formatTimeAgo;
  7494. exports.getSSRHandler = getSSRHandler;
  7495. exports.mapGamepadToXbox360Controller = mapGamepadToXbox360Controller;
  7496. exports.onClickOutside = onClickOutside;
  7497. exports.onKeyDown = onKeyDown;
  7498. exports.onKeyPressed = onKeyPressed;
  7499. exports.onKeyStroke = onKeyStroke;
  7500. exports.onKeyUp = onKeyUp;
  7501. exports.onLongPress = onLongPress;
  7502. exports.onStartTyping = onStartTyping;
  7503. exports.setSSRHandler = setSSRHandler;
  7504. exports.templateRef = templateRef;
  7505. exports.unrefElement = unrefElement;
  7506. exports.useActiveElement = useActiveElement;
  7507. exports.useAnimate = useAnimate;
  7508. exports.useAsyncQueue = useAsyncQueue;
  7509. exports.useAsyncState = useAsyncState;
  7510. exports.useBase64 = useBase64;
  7511. exports.useBattery = useBattery;
  7512. exports.useBluetooth = useBluetooth;
  7513. exports.useBreakpoints = useBreakpoints;
  7514. exports.useBroadcastChannel = useBroadcastChannel;
  7515. exports.useBrowserLocation = useBrowserLocation;
  7516. exports.useCached = useCached;
  7517. exports.useClipboard = useClipboard;
  7518. exports.useClipboardItems = useClipboardItems;
  7519. exports.useCloned = useCloned;
  7520. exports.useColorMode = useColorMode;
  7521. exports.useConfirmDialog = useConfirmDialog;
  7522. exports.useCssVar = useCssVar;
  7523. exports.useCurrentElement = useCurrentElement;
  7524. exports.useCycleList = useCycleList;
  7525. exports.useDark = useDark;
  7526. exports.useDebouncedRefHistory = useDebouncedRefHistory;
  7527. exports.useDeviceMotion = useDeviceMotion;
  7528. exports.useDeviceOrientation = useDeviceOrientation;
  7529. exports.useDevicePixelRatio = useDevicePixelRatio;
  7530. exports.useDevicesList = useDevicesList;
  7531. exports.useDisplayMedia = useDisplayMedia;
  7532. exports.useDocumentVisibility = useDocumentVisibility;
  7533. exports.useDraggable = useDraggable;
  7534. exports.useDropZone = useDropZone;
  7535. exports.useElementBounding = useElementBounding;
  7536. exports.useElementByPoint = useElementByPoint;
  7537. exports.useElementHover = useElementHover;
  7538. exports.useElementSize = useElementSize;
  7539. exports.useElementVisibility = useElementVisibility;
  7540. exports.useEventBus = useEventBus;
  7541. exports.useEventListener = useEventListener;
  7542. exports.useEventSource = useEventSource;
  7543. exports.useEyeDropper = useEyeDropper;
  7544. exports.useFavicon = useFavicon;
  7545. exports.useFetch = useFetch;
  7546. exports.useFileDialog = useFileDialog;
  7547. exports.useFileSystemAccess = useFileSystemAccess;
  7548. exports.useFocus = useFocus;
  7549. exports.useFocusWithin = useFocusWithin;
  7550. exports.useFps = useFps;
  7551. exports.useFullscreen = useFullscreen;
  7552. exports.useGamepad = useGamepad;
  7553. exports.useGeolocation = useGeolocation;
  7554. exports.useIdle = useIdle;
  7555. exports.useImage = useImage;
  7556. exports.useInfiniteScroll = useInfiniteScroll;
  7557. exports.useIntersectionObserver = useIntersectionObserver;
  7558. exports.useKeyModifier = useKeyModifier;
  7559. exports.useLocalStorage = useLocalStorage;
  7560. exports.useMagicKeys = useMagicKeys;
  7561. exports.useManualRefHistory = useManualRefHistory;
  7562. exports.useMediaControls = useMediaControls;
  7563. exports.useMediaQuery = useMediaQuery;
  7564. exports.useMemoize = useMemoize;
  7565. exports.useMemory = useMemory;
  7566. exports.useMounted = useMounted;
  7567. exports.useMouse = useMouse;
  7568. exports.useMouseInElement = useMouseInElement;
  7569. exports.useMousePressed = useMousePressed;
  7570. exports.useMutationObserver = useMutationObserver;
  7571. exports.useNavigatorLanguage = useNavigatorLanguage;
  7572. exports.useNetwork = useNetwork;
  7573. exports.useNow = useNow;
  7574. exports.useObjectUrl = useObjectUrl;
  7575. exports.useOffsetPagination = useOffsetPagination;
  7576. exports.useOnline = useOnline;
  7577. exports.usePageLeave = usePageLeave;
  7578. exports.useParallax = useParallax;
  7579. exports.useParentElement = useParentElement;
  7580. exports.usePerformanceObserver = usePerformanceObserver;
  7581. exports.usePermission = usePermission;
  7582. exports.usePointer = usePointer;
  7583. exports.usePointerLock = usePointerLock;
  7584. exports.usePointerSwipe = usePointerSwipe;
  7585. exports.usePreferredColorScheme = usePreferredColorScheme;
  7586. exports.usePreferredContrast = usePreferredContrast;
  7587. exports.usePreferredDark = usePreferredDark;
  7588. exports.usePreferredLanguages = usePreferredLanguages;
  7589. exports.usePreferredReducedMotion = usePreferredReducedMotion;
  7590. exports.usePrevious = usePrevious;
  7591. exports.useRafFn = useRafFn;
  7592. exports.useRefHistory = useRefHistory;
  7593. exports.useResizeObserver = useResizeObserver;
  7594. exports.useScreenOrientation = useScreenOrientation;
  7595. exports.useScreenSafeArea = useScreenSafeArea;
  7596. exports.useScriptTag = useScriptTag;
  7597. exports.useScroll = useScroll;
  7598. exports.useScrollLock = useScrollLock;
  7599. exports.useSessionStorage = useSessionStorage;
  7600. exports.useShare = useShare;
  7601. exports.useSorted = useSorted;
  7602. exports.useSpeechRecognition = useSpeechRecognition;
  7603. exports.useSpeechSynthesis = useSpeechSynthesis;
  7604. exports.useStepper = useStepper;
  7605. exports.useStorage = useStorage;
  7606. exports.useStorageAsync = useStorageAsync;
  7607. exports.useStyleTag = useStyleTag;
  7608. exports.useSupported = useSupported;
  7609. exports.useSwipe = useSwipe;
  7610. exports.useTemplateRefsList = useTemplateRefsList;
  7611. exports.useTextDirection = useTextDirection;
  7612. exports.useTextSelection = useTextSelection;
  7613. exports.useTextareaAutosize = useTextareaAutosize;
  7614. exports.useThrottledRefHistory = useThrottledRefHistory;
  7615. exports.useTimeAgo = useTimeAgo;
  7616. exports.useTimeoutPoll = useTimeoutPoll;
  7617. exports.useTimestamp = useTimestamp;
  7618. exports.useTitle = useTitle;
  7619. exports.useTransition = useTransition;
  7620. exports.useUrlSearchParams = useUrlSearchParams;
  7621. exports.useUserMedia = useUserMedia;
  7622. exports.useVModel = useVModel;
  7623. exports.useVModels = useVModels;
  7624. exports.useVibrate = useVibrate;
  7625. exports.useVirtualList = useVirtualList;
  7626. exports.useWakeLock = useWakeLock;
  7627. exports.useWebNotification = useWebNotification;
  7628. exports.useWebSocket = useWebSocket;
  7629. exports.useWebWorker = useWebWorker;
  7630. exports.useWebWorkerFn = useWebWorkerFn;
  7631. exports.useWindowFocus = useWindowFocus;
  7632. exports.useWindowScroll = useWindowScroll;
  7633. exports.useWindowSize = useWindowSize;
  7634. Object.keys(shared).forEach(function (k) {
  7635. if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
  7636. enumerable: true,
  7637. get: function () { return shared[k]; }
  7638. });
  7639. });
  7640. })(this.VueUse = this.VueUse || {}, VueUse, Vue);