mirror of
https://github.com/shadoll/sLogos.git
synced 2025-12-20 11:32:01 +00:00
feat: implement SVG source copying functionality and add Notification component
This commit is contained in:
35
src/utils/svgSource.js
Normal file
35
src/utils/svgSource.js
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user