// URL state management using base64 encoding export const encodeToUrl = (content: string): string => { try { const base64 = btoa(unescape(encodeURIComponent(content))); return base64; } catch (error) { console.error('Error encoding to base64:', error); return ''; } }; export const decodeFromUrl = (base64: string): string => { try { const decoded = decodeURIComponent(escape(atob(base64))); return decoded; } catch (error) { console.error('Error decoding from base64:', error); return ''; } }; export const getContentFromUrl = (): string => { const hash = window.location.hash.slice(1); // Remove the '#' if (hash) { return decodeFromUrl(hash); } return ''; }; export const updateUrlWithContent = (content: string): void => { const encoded = encodeToUrl(content); if (encoded) { window.history.replaceState(null, '', `#${encoded}`); } else { window.history.replaceState(null, '', window.location.pathname); } };