index.js 269 KB

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