@yhattav/react-component-cursor
Version:
A lightweight, TypeScript-first React library for creating beautiful custom cursors with SSR support, smooth animations, and zero dependencies. Perfect for interactive websites, games, and creative applications.
1 lines • 3.1 kB
Source Map (JSON)
{"version":3,"sources":["../src/utils/ssr.ts"],"sourcesContent":["/**\n * SSR (Server-Side Rendering) utility functions\n * Provides safe detection and handling of server-side rendering environments\n */\n\n/**\n * Detects if the code is running in a server-side rendering environment\n * @returns true if running on server (SSR), false if running in browser\n */\nexport const isSSR = (): boolean => {\n return typeof window === 'undefined';\n};\n\n/**\n * Detects if the code is running in a browser environment\n * @returns true if running in browser, false if running on server\n */\nexport const isBrowser = (): boolean => {\n return typeof window !== 'undefined';\n};\n\n/**\n * Detects if the code is running on a mobile/touch device\n * Uses multiple detection methods for better accuracy\n * @returns true if running on mobile/touch device, false otherwise\n */\nexport const isMobileDevice = (): boolean => {\n if (isSSR()) {\n return false;\n }\n\n // Check for touch capability\n const hasTouchCapability = 'ontouchstart' in window || \n navigator.maxTouchPoints > 0 || \n (navigator as any).msMaxTouchPoints > 0;\n\n // Check user agent for mobile patterns\n const mobileUserAgentPattern = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;\n const isMobileUserAgent = mobileUserAgentPattern.test(navigator.userAgent);\n\n // Check for small screen size (mobile viewport)\n const isSmallScreen = window.innerWidth <= 768 || window.innerHeight <= 768;\n\n // Device is considered mobile if it has touch AND (mobile user agent OR small screen)\n return hasTouchCapability && (isMobileUserAgent || isSmallScreen);\n};\n\n/**\n * Safely executes a function only in browser environment\n * @param fn Function to execute in browser\n * @param fallback Optional fallback value to return in SSR\n * @returns Result of function or fallback value\n */\nexport const browserOnly = <T>(fn: () => T, fallback?: T): T | undefined => {\n if (isBrowser()) {\n return fn();\n }\n return fallback;\n};\n\n/**\n * Safely gets the document object, handling SSR\n * @returns document if in browser, null if in SSR\n */\nexport const safeDocument = (): Document | null => {\n return isBrowser() ? document : null;\n};\n\n/**\n * Safely gets the window object, handling SSR\n * @returns window if in browser, null if in SSR\n */\nexport const safeWindow = (): Window | null => {\n return isBrowser() ? window : null;\n}; "],"mappings":";;;;;;;;;;;;;;;;;;AASO,IAAM,QAAQ,MAAe;AAClC,SAAO,OAAO,WAAW;AAC3B;AAMO,IAAM,YAAY,MAAe;AACtC,SAAO,OAAO,WAAW;AAC3B;AAOO,IAAM,iBAAiB,MAAe;AAC3C,MAAI,MAAM,GAAG;AACX,WAAO;AAAA,EACT;AAGA,QAAM,qBAAqB,kBAAkB,UACnB,UAAU,iBAAiB,KAC1B,UAAkB,mBAAmB;AAGhE,QAAM,yBAAyB;AAC/B,QAAM,oBAAoB,uBAAuB,KAAK,UAAU,SAAS;AAGzE,QAAM,gBAAgB,OAAO,cAAc,OAAO,OAAO,eAAe;AAGxE,SAAO,uBAAuB,qBAAqB;AACrD;AAQO,IAAM,cAAc,CAAI,IAAa,aAAgC;AAC1E,MAAI,UAAU,GAAG;AACf,WAAO,GAAG;AAAA,EACZ;AACA,SAAO;AACT;AAMO,IAAM,eAAe,MAAuB;AACjD,SAAO,UAAU,IAAI,WAAW;AAClC;AAMO,IAAM,aAAa,MAAqB;AAC7C,SAAO,UAAU,IAAI,SAAS;AAChC;","names":[]}