feat: implement SVG source copying functionality and add Notification component

This commit is contained in:
sHa
2025-05-14 13:48:42 +03:00
parent e9b58a6592
commit 554861c940
4 changed files with 170 additions and 70 deletions

35
src/utils/svgSource.js Normal file
View File

@@ -0,0 +1,35 @@
/**
* Fetches the SVG source code from a file path
*
* @param {string} path - Path to the SVG file
* @returns {Promise<string>} - The SVG source code
*/
export async function fetchSvgSource(path) {
try {
const response = await fetch(path);
if (!response.ok) {
throw new Error(`Failed to fetch SVG: ${response.status}`);
}
return await response.text();
} catch (error) {
console.error('Error fetching SVG source:', error);
throw error;
}
}
/**
* Copy SVG source to clipboard
*
* @param {string} path - Path to the SVG file
* @returns {Promise<boolean>} - True if successful, false otherwise
*/
export async function copySvgSource(path) {
try {
const svgSource = await fetchSvgSource(path);
await navigator.clipboard.writeText(svgSource);
return true;
} catch (error) {
console.error('Error copying SVG source:', error);
return false;
}
}