diff --git a/package.json b/package.json index 265a0d9..51dc1c4 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,13 @@ "check:size": "cd ./check-size && npm run start", "test": "vitest run", "lint": "prettier --plugin-search-dir . --check . && eslint .", - "format": "prettier --plugin-search-dir . --write ." + "format": "prettier --plugin-search-dir . --write .", + "dev:figma": "concurrently -n plugin,svelte 'npm run build:plugin -- --watch --define:SITE_URL=\\\"http://localhost:5173?figma=1\\\"' 'npm run dev'", + "build:plugin": "esbuild src/figma/code.ts --bundle --target=es6 --loader:.svg=text --outfile=src/figma/dist/code.js", + "build:figma": "concurrently -n plugin,svelte 'npm run build:plugin -- --define:SITE_URL=\\\"$npm_package_config_siteURL\\\"' 'npm run build'" }, "dependencies": { + "@figma/plugin-typings": "^1.82.0", "@upstash/ratelimit": "1.0.0", "@upstash/redis": "1.25.2", "bits-ui": "0.11.8", @@ -45,6 +49,8 @@ "@typescript-eslint/eslint-plugin": "6.14.0", "@typescript-eslint/parser": "6.14.0", "autoprefixer": "10.4.16", + "concurrently": "^8.2.2", + "esbuild": "^0.19.10", "eslint": "8.56.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.35.1", @@ -61,5 +67,8 @@ "typescript": "5.3.3", "vite": "5.0.10", "vitest": "1.0.4" + }, + "config": { + "siteURL": "https://svgl.vercel.app?figma=1" } } diff --git a/src/components/svgCard.svelte b/src/components/svgCard.svelte index 198c3a0..909e660 100644 --- a/src/components/svgCard.svelte +++ b/src/components/svgCard.svelte @@ -10,14 +10,26 @@ import { flyAndScale } from '@/utils/flyAndScale'; // Icons: - import { CopyIcon, DownloadIcon, LinkIcon, PackageIcon, PaintBucket } from 'lucide-svelte'; + import { CopyIcon, DownloadIcon, LinkIcon, PackageIcon, PaintBucket, ChevronsRight } from 'lucide-svelte'; // Main Card: import CardSpotlight from './cardSpotlight.svelte'; import { DropdownMenu } from 'bits-ui'; + // Figma + import { onMount } from "svelte"; + import { copyToClipboard as figmaCopyToClipboard } from '@/figma/copy-to-clipboard'; + import { insertSVG as figmaInsertSVG } from '@/figma/insert-svg'; + + // Props: export let svgInfo: iSVG; + + let isInFigma = false + onMount(() => { + const searchParams = new URLSearchParams(window.location.search); + isInFigma = searchParams.get('figma') === '1'; + }); // Download SVG: const downloadSvg = (url?: string) => { @@ -56,18 +68,30 @@ const data = { [MIMETYPE]: getSvgContent(url, true) }; - try { - const clipboardItem = new ClipboardItem(data); - await navigator.clipboard.write([clipboardItem]); - } catch (error) { + + if(isInFigma) { const content = (await getSvgContent(url, false)) as string; - await navigator.clipboard.writeText(content); + figmaCopyToClipboard(content); + } else { + try { + const clipboardItem = new ClipboardItem(data); + await navigator.clipboard.write([clipboardItem]); + } catch (error) { + const content = (await getSvgContent(url, false)) as string; + await navigator.clipboard.writeText(content); + } } + toast.success('Copied to clipboard!', { description: `${svgInfo.title} - ${svgInfo.category}` }); }; + const insertSVG = async (url?: string) => { + const content = (await getSvgContent(url, false)) as string; + figmaInsertSVG(content); + } + // Icon Stroke & Size: let iconStroke = 1.8; let iconSize = 16; @@ -102,6 +126,38 @@
+ {#if isInFigma} + + {/if} + +