2 lines
5.2 KiB
JavaScript
2 lines
5.2 KiB
JavaScript
import{r as s,c as l,o as ae,aO as re}from"./index-QAlcqU00.js";function ue(){const o=s(!1),M=s(!1),i=s({width:0,height:0}),T=s("portrait"),v=s("desktop"),f=s(!1),d=s(null),h=s(!1),w=l(()=>i.value.width<768),g=l(()=>i.value.width>=768&&i.value.width<1024),X=l(()=>i.value.width>=1024),Y=l(()=>w.value?"layout-mobile":g.value?"layout-tablet":"layout-desktop"),B=l(()=>w.value?"grid-cols-1":g.value?"grid-cols-2":"grid-cols-3"),O=l(()=>w.value?5:g.value?10:20),y={xs:320,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},S=()=>{i.value={width:window.innerWidth,height:window.innerHeight},o.value=i.value.width<y.md,M.value=i.value.width>=y.md&&i.value.width<y.lg,o.value?v.value="mobile":M.value?v.value="tablet":v.value="desktop",T.value=i.value.width>i.value.height?"landscape":"portrait"},R=()=>{f.value="ontouchstart"in window||navigator.maxTouchPoints>0},x=()=>{S()},z=()=>{setTimeout(S,100)},b=e=>{e.preventDefault(),d.value=e},$=async()=>{if(!d.value)return!1;try{const e=await d.value.prompt();return console.log("Install prompt result:",e),e.outcome==="accepted"?(d.value=null,h.value=!0,!0):!1}catch(e){return console.error("Failed to install app:",e),!1}},G=()=>{h.value=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0},Q=(e,t={})=>{if(!f.value)return;let n=0,u=0,r=0;const L=a=>{const m=a.touches[0];n=m.clientX,u=m.clientY,r=Date.now()},P=a=>{var _,q,A,F,D,V;const m=a.changedTouches[0],ne=m.clientX,oe=m.clientY,ie=Date.now(),c=ne-n,p=oe-u,E=ie-r,C=50,I=300;Math.abs(c)>Math.abs(p)&&Math.abs(c)>C&&E<I?c>0?(_=t.onSwipeRight)==null||_.call(t,a):(q=t.onSwipeLeft)==null||q.call(t,a):Math.abs(p)>C&&E<I&&(p>0?(A=t.onSwipeDown)==null||A.call(t,a):(F=t.onSwipeUp)==null||F.call(t,a)),Math.abs(c)<10&&Math.abs(p)<10&&E<300&&((D=t.onTap)==null||D.call(t,a)),E>500&&Math.abs(c)<10&&Math.abs(p)<10&&((V=t.onLongPress)==null||V.call(t,a))};return e.addEventListener("touchstart",L,{passive:!0}),e.addEventListener("touchend",P,{passive:!0}),()=>{e.removeEventListener("touchstart",L),e.removeEventListener("touchend",P)}},U=e=>{if(!o.value)return e;const t=e.filter(n=>n.priority==="high"||n.essential);return t.length===0?e.slice(0,3):t},W=e=>({items:e,collapsed:!0,toggle(){this.collapsed=!this.collapsed},close(){this.collapsed=!0}}),H=()=>{o.value&&(document.documentElement.style.setProperty("--animation-duration","0.2s"),document.body.classList.add("mobile-optimized"),f.value&&document.body.classList.add("touch-device"))},j=(e,t="medium")=>{const u={small:o.value?"_mobile":"_small",medium:o.value?"_mobile":"_medium",large:o.value?"_tablet":"_large"}[t]||"_medium",[r,L]=e.split(".");return`${r}${u}.${L}`},J=(e="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no")=>{let t=document.querySelector("meta[name=viewport]");t||(t=document.createElement("meta"),t.name="viewport",document.head.appendChild(t)),t.content=e},K=()=>{const e=getComputedStyle(document.documentElement);return{top:e.getPropertyValue("--safe-area-inset-top")||"0px",right:e.getPropertyValue("--safe-area-inset-right")||"0px",bottom:e.getPropertyValue("--safe-area-inset-bottom")||"0px",left:e.getPropertyValue("--safe-area-inset-left")||"0px"}},N=(e=100)=>{"vibrate"in navigator&&navigator.vibrate(e)},Z=async()=>{if("wakeLock"in navigator)try{const e=await navigator.wakeLock.request("screen");return console.log("Screen wake lock acquired"),e}catch(e){console.error("Failed to acquire wake lock:",e)}return null},k=e=>{if(!o.value)return;e.querySelectorAll("input, select, textarea").forEach(n=>{(n.type==="text"||n.type==="email"||n.type==="password")&&(n.style.fontSize="16px"),n.name==="email"&&n.setAttribute("autocomplete","email"),n.type==="number"&&n.setAttribute("inputmode","numeric"),n.type==="tel"&&n.setAttribute("inputmode","tel")})},ee=()=>({cardSpacing:o.value?"space-y-3":"space-y-4",padding:o.value?"p-4":"p-6",margin:o.value?"m-2":"m-4",fontSize:o.value?"text-sm":"text-base",buttonSize:o.value?"sm":"md",modalSize:o.value?"full":"lg"}),te=()=>{var e,t;if("performance"in window){const n=performance.getEntriesByType("navigation")[0],u=performance.getEntriesByType("paint");return{loadTime:n.loadEventEnd-n.loadEventStart,domContentLoaded:n.domContentLoadedEventEnd-n.domContentLoadedEventStart,firstPaint:(e=u.find(r=>r.name==="first-paint"))==null?void 0:e.startTime,firstContentfulPaint:(t=u.find(r=>r.name==="first-contentful-paint"))==null?void 0:t.startTime}}return null};return ae(()=>{S(),R(),G(),H(),J(),window.addEventListener("resize",x),window.addEventListener("orientationchange",z),window.addEventListener("beforeinstallprompt",b),window.matchMedia("(display-mode: standalone)").addListener(t=>{h.value=t.matches})}),re(()=>{window.removeEventListener("resize",x),window.removeEventListener("orientationchange",z),window.removeEventListener("beforeinstallprompt",b)}),{isMobile:o,isTablet:M,screenSize:i,orientation:T,deviceType:v,touchSupport:f,installPrompt:d,isInstalled:h,isSmallScreen:w,isMediumScreen:g,isLargeScreen:X,layoutClass:Y,cardGridCols:B,tablePageSize:O,breakpoints:y,updateScreenInfo:S,installApp:$,setupTouchGestures:Q,optimizeTableForMobile:U,createMobileMenu:W,getResponsiveImageSrc:j,getSafeAreaInsets:K,vibrate:N,requestWakeLock:Z,optimizeFormForMobile:k,getMobileLayoutConfig:ee,measurePerformance:te}}export{ue as u};
|