a3b3e39f4b3a852f458996cd702a917329409c11f5b997a4c1a57259e84f5744bbf855522a77410e54ed6159514ef4ed75dab868f235e5a5498f0366e9cc3b 221 KB

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