9461f66736ad4679106536b6c0de44ea09042be80248000f7e26cddf1ed963e187596e82ec2e48c487417c6cbbc9cef3cde6ca88aa360f550ab6b30ee553ec 239 KB

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