mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-05-18 11:56:26 +02:00
* update nitro * try this? * Try this * update vercel output * Add await * Fix endpoints * Adjust 404 catch all * Fix output * Adjust react in api * Fix types * Remove @resvg/resvg-wasm * Format code * Fix failing check * Apply feedback * Format code
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { eventHandler, setResponseHeader, defaultContentType } from 'h3';
|
|
import { renderToString } from 'react-dom/server';
|
|
import React from 'react';
|
|
import Icon from 'lucide-react/src/Icon';
|
|
import type { IconNode } from 'lucide-react/src/types';
|
|
import { parseSync } from 'svgson';
|
|
|
|
export default eventHandler((event) => {
|
|
const { params } = event.context;
|
|
|
|
const [strokeWidth, svgData] = params.data.split('/');
|
|
const data = svgData.slice(0, -4);
|
|
|
|
const src = Buffer.from(data, 'base64').toString('utf8');
|
|
const iconNode = parseSync(src.includes('<svg') ? src : `<svg>${src}</svg>`).children.map(
|
|
({ name, attributes }) => [name, attributes],
|
|
) as IconNode;
|
|
|
|
defaultContentType(event, 'image/svg+xml');
|
|
setResponseHeader(event, 'Cache-Control', 'public,max-age=31536000');
|
|
|
|
return renderToString(
|
|
<Icon
|
|
iconNode={iconNode}
|
|
strokeWidth={strokeWidth}
|
|
>
|
|
<style>
|
|
{`@media screen and (prefers-color-scheme: light) {
|
|
svg { fill: transparent !important; }
|
|
}
|
|
@media screen and (prefers-color-scheme: dark) {
|
|
svg { stroke: #fff; fill: transparent !important; }
|
|
}`}
|
|
</style>
|
|
</Icon>,
|
|
);
|
|
});
|