| 
									
										
										
										
											2023-07-18 09:45:17 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StorageMock { | 
					
						
							|  |  |  |   data: Record<string, string> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor() { | 
					
						
							|  |  |  |     this.data = {} as Record<string, string> | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setItem(name: string, value: string) { | 
					
						
							|  |  |  |     this.data[name] = value | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getItem(name: string) { | 
					
						
							|  |  |  |     return this.data[name] || null | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   removeItem(name: string) { | 
					
						
							|  |  |  |     delete this.data[name] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   clear() { | 
					
						
							|  |  |  |     this.data = {} | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let localStorage, sessionStorage | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try { | 
					
						
							|  |  |  |   localStorage = globalThis.localStorage | 
					
						
							|  |  |  |   sessionStorage = globalThis.sessionStorage | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-04-14 11:27:14 +08:00
										 |  |  | catch { | 
					
						
							| 
									
										
										
										
											2023-07-18 09:45:17 +08:00
										 |  |  |   localStorage = new StorageMock() | 
					
						
							|  |  |  |   sessionStorage = new StorageMock() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Object.defineProperty(globalThis, 'localStorage', { | 
					
						
							|  |  |  |   value: localStorage, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Object.defineProperty(globalThis, 'sessionStorage', { | 
					
						
							|  |  |  |   value: sessionStorage, | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  | const BrowserInitor = ({ | 
					
						
							| 
									
										
										
										
											2023-07-18 09:45:17 +08:00
										 |  |  |   children, | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  | }: { children: React.ReactNode }) => { | 
					
						
							| 
									
										
										
										
											2023-07-18 09:45:17 +08:00
										 |  |  |   return children | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  | export default BrowserInitor |