mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
✨ Initial commit with Sveltekit + format files
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
const MIMETYPE = 'text/plain';
|
||||
|
||||
export const clipboard = async (content: string) => {
|
||||
try {
|
||||
const clipboardItem = new ClipboardItem({
|
||||
[MIMETYPE]: new Blob([content], { type: MIMETYPE })
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
await navigator.clipboard.write([clipboardItem]);
|
||||
}, 200);
|
||||
} catch (error) {
|
||||
await navigator.clipboard.writeText(content);
|
||||
}
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
import { clsx, type ClassValue } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import { cubicOut } from 'svelte/easing';
|
||||
import type { TransitionConfig } from 'svelte/transition';
|
||||
|
||||
type FlyAndScaleParams = {
|
||||
y?: number;
|
||||
x?: number;
|
||||
start?: number;
|
||||
duration?: number;
|
||||
};
|
||||
export const flyAndScale = (
|
||||
node: Element,
|
||||
params: FlyAndScaleParams = { y: -8, x: 0, start: 0.95, duration: 150 }
|
||||
): TransitionConfig => {
|
||||
const style = getComputedStyle(node);
|
||||
const transform = style.transform === 'none' ? '' : style.transform;
|
||||
const scaleConversion = (valueA: number, scaleA: [number, number], scaleB: [number, number]) => {
|
||||
const [minA, maxA] = scaleA;
|
||||
const [minB, maxB] = scaleB;
|
||||
const percentage = (valueA - minA) / (maxA - minA);
|
||||
const valueB = percentage * (maxB - minB) + minB;
|
||||
return valueB;
|
||||
};
|
||||
const styleToString = (style: Record<string, number | string | undefined>): string => {
|
||||
return Object.keys(style).reduce((str, key) => {
|
||||
if (style[key] === undefined) return str;
|
||||
return str + key + ':' + style[key] + ';';
|
||||
}, '');
|
||||
};
|
||||
return {
|
||||
duration: params.duration ?? 200,
|
||||
delay: 0,
|
||||
css: (t) => {
|
||||
const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0]);
|
||||
const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0]);
|
||||
const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1]);
|
||||
return styleToString({
|
||||
transform: transform + 'translate3d(' + x + 'px, ' + y + 'px, 0) scale(' + scale + ')',
|
||||
opacity: t
|
||||
});
|
||||
},
|
||||
easing: cubicOut
|
||||
};
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
export async function fetchGitHubStars() {
|
||||
const res = await fetch('https://api.github.com/repos/pheralb/svgl');
|
||||
const response = await res.json();
|
||||
const starsFormated =
|
||||
response.stargazers_count > 1000
|
||||
? `${(response.stargazers_count / 1000).toFixed(1)}K`
|
||||
: response.stargazers_count;
|
||||
|
||||
return starsFormated;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
export const parseSvgContent = (content: string, framework: 'Vue' | 'Svelte') => {
|
||||
if (content.includes('<?xml')) {
|
||||
content = content.replace(/<\?xml[^>]*\?>/i, '');
|
||||
}
|
||||
// Regular expression to match <style> tags in the SVG content
|
||||
const styleTagRegex = /<style[^>]*>([\s\S]*?)<\/style>/gi;
|
||||
|
||||
// Extract styles and store them in an array
|
||||
const styles = [];
|
||||
let matched;
|
||||
while ((matched = styleTagRegex.exec(content)) !== null) {
|
||||
styles.push(matched[1]); // Add the style content (not including the style tag)
|
||||
}
|
||||
|
||||
// Remove <style> tags from the SVG content
|
||||
const templateContent = content.replace(styleTagRegex, '');
|
||||
|
||||
const componentStyle = styles.length
|
||||
? `<style${framework === 'Vue' ? ' scoped' : ''}>\n${styles.join('\n')}\n</style>`
|
||||
: '';
|
||||
|
||||
return {
|
||||
componentStyle,
|
||||
templateContent
|
||||
};
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
import { optimize } from 'svgo';
|
||||
|
||||
export const getPrefixFromSvgUrl = (svgUrl: string) => {
|
||||
return svgUrl.split('/').pop()!.replace('.svg', '').split('-').join('_');
|
||||
};
|
||||
|
||||
export const prefixSvgIds = (content: string, prefix: string): string => {
|
||||
const result = optimize(content, {
|
||||
plugins: [
|
||||
{
|
||||
name: 'prefixIds',
|
||||
params: {
|
||||
prefix
|
||||
}
|
||||
}
|
||||
],
|
||||
multipass: false
|
||||
});
|
||||
|
||||
return (result as { data: string }).data;
|
||||
};
|
||||
Reference in New Issue
Block a user