|
1 | 1 | import type { BuiltInParserName as PrettierParser } from 'prettier' |
2 | 2 | import { encodeSvgForCss } from '@iconify/utils' |
3 | 3 | import { buildIcon, loadIcon } from 'iconify-icon' |
4 | | -import { getTransformedId } from '../store' |
| 4 | +import { getTransformedId, useCurrentCollection } from '../store' |
5 | 5 | import Base64 from './base64' |
6 | 6 | import { HtmlToJSX } from './htmlToJsx' |
7 | 7 | import { prettierCode } from './prettier' |
@@ -42,15 +42,19 @@ export const SnippetMap: Record<string, Record<string, Snippet>> = { |
42 | 42 |
|
43 | 43 | const API_ENTRY = 'https://api.iconify.design' |
44 | 44 |
|
| 45 | +const collectionDetails = useCurrentCollection() |
| 46 | + |
45 | 47 | export async function getSvgLocal(icon: string, size = '1em', color = 'currentColor') { |
| 48 | + const currentUsedCollection = collectionDetails.value |
46 | 49 | const data = await loadIcon(icon) |
47 | 50 | if (!data) |
48 | 51 | return |
49 | 52 | const built = buildIcon(data, { height: size }) |
50 | 53 | if (!built) |
51 | 54 | return |
| 55 | + const license = `<!-- Icon from ${currentUsedCollection?.name} by ${currentUsedCollection?.author?.name} - ${currentUsedCollection?.license?.url} -->` |
52 | 56 | const xlink = built.body.includes('xlink:') ? ' xmlns:xlink="http://www.w3.org/1999/xlink"' : '' |
53 | | - return `<svg xmlns="http://www.w3.org/2000/svg"${xlink} ${Object.entries(built.attributes).map(([k, v]) => `${k}="${v}"`).join(' ')}>${built.body}</svg>`.replaceAll('currentColor', color) |
| 57 | + return `<svg xmlns="http://www.w3.org/2000/svg"${xlink} ${Object.entries(built.attributes).map(([k, v]) => `${k}="${v}"`).join(' ')}>${license}${built.body}</svg>`.replaceAll('currentColor', color) |
54 | 58 | } |
55 | 59 |
|
56 | 60 | export async function getSvg(icon: string, size = '1em', color = 'currentColor') { |
@@ -182,7 +186,7 @@ export function SvgToReactNative(svg: string, name: string, snippet: boolean) { |
182 | 186 | } |
183 | 187 |
|
184 | 188 | function generateImports(usedComponents: string[]): string { |
185 | | - // Separate Svg from the other components |
| 189 | + // Separate Svg from the other components |
186 | 190 | const svgIndex = usedComponents.indexOf('Svg') |
187 | 191 | if (svgIndex !== -1) |
188 | 192 | usedComponents.splice(svgIndex, 1) |
|
0 commit comments