index.cjs 206 KB

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