index.iife.js 222 KB

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