Initial commit with Sveltekit + format files

This commit is contained in:
pheralb
2025-08-21 10:26:07 +01:00
parent ca4f397e0a
commit 459457a7e1
97 changed files with 3892 additions and 9893 deletions
-15
View File
@@ -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);
}
};
-6
View File
@@ -1,6 +0,0 @@
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
-43
View File
@@ -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
};
};
-10
View File
@@ -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;
}
-26
View File
@@ -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
};
};
-21
View File
@@ -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;
};