index.cjs 224 KB

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