diff --git a/docs/.vitepress/api/gh-icon/symmetry/[...data].get.ts b/docs/.vitepress/api/gh-icon/symmetry/[...data].get.ts new file mode 100644 index 000000000..573be976e --- /dev/null +++ b/docs/.vitepress/api/gh-icon/symmetry/[...data].get.ts @@ -0,0 +1,55 @@ +import { eventHandler, setResponseHeader, defaultContentType } from 'h3'; +import { renderToString } from 'react-dom/server'; +import { createElement } from 'react'; +import Diff from '../../../lib/SvgPreview/Diff.tsx'; + +export default eventHandler((event) => { + const { params } = event.context; + + const pathData = params.data.split('/'); + const data = pathData.at(-1).slice(0, -4); + const [operation] = pathData; + + const newSrc = Buffer.from(data, 'base64') + .toString('utf8') + .replaceAll('\n', '') + .replace(/]*>|<\/svg>/g, ''); + + const width = parseInt( + (newSrc.includes('${newSrc}`; + } else if (operation === 'flip-horizontal') { + oldSrc = `${newSrc}`; + } else if (operation === 'flip-vertical') { + oldSrc = `${newSrc}`; + } else if (operation === 'flip-backslash') { + oldSrc = `${newSrc}`; + } else if (operation === 'flip-slash') { + oldSrc = `${newSrc}`; + } else { + return ''; + } + + const svg = Buffer.from( + // We can't use jsx here, is not supported here by nitro. + renderToString( + createElement(Diff, { oldSrc, newSrc, showGrid: true, height, width }, children), + ), + ).toString('utf8'); + + defaultContentType(event, 'image/svg+xml'); + setResponseHeader(event, 'Cache-Control', 'public,max-age=31536000'); + + return svg; +}); diff --git a/scripts/generateChangedIconsCommentMarkup.mts b/scripts/generateChangedIconsCommentMarkup.mts index e1cc65cb0..4e1d3ec66 100644 --- a/scripts/generateChangedIconsCommentMarkup.mts +++ b/scripts/generateChangedIconsCommentMarkup.mts @@ -52,7 +52,8 @@ const getImageTagsByFiles = ( const svgFiles = await readSvgDirectory(ICONS_DIR); const svgFilePaths = svgFiles.map((file) => `icons/${file}`); -const iconsFilteredByName = (search: string) => svgFilePaths.filter((file) => file.includes(search)); +const iconsFilteredByName = (search: string) => + svgFilePaths.filter((file) => file.includes(search)); const cohesionRandomImageTags = getImageTagsByFiles( shuffleArray(svgFilePaths).slice(0, changedFiles.length), @@ -120,6 +121,30 @@ const changeFilesDiffImageTags = getImageTagsByFiles( 400, ).join(' '); +const changeFilesSymmetryImageTagsRotate180 = getImageTagsByFiles( + changedFiles, + () => `${BASE_URL}/symmetry/rotate-180`, + 400, +).join(' '); + +const changeFilesSymmetryImageTagsFlipHorizontal = getImageTagsByFiles( + changedFiles, + () => `${BASE_URL}/symmetry/flip-horizontal`, + 400, +).join(' '); + +const changeFilesSymmetryImageTagsFlipVertical = getImageTagsByFiles( + changedFiles, + () => `${BASE_URL}/symmetry/flip-vertical`, + 400, +).join(' '); + +const changeFilesSymmetryImageTagsFlipSlash = getImageTagsByFiles( + changedFiles, + () => `${BASE_URL}/symmetry/flip-slash`, + 400, +).join(' '); + const readyToUseCode = changedFiles .map((changedFile) => { const svgContent = fs.readFileSync(path.join(process.cwd(), changedFile), 'utf-8'); @@ -179,6 +204,17 @@ ${changeFilesXRayImageTags} ${changeFilesDiffImageTags}
+Icon Symmetry +

Flip Horizontal

+${changeFilesSymmetryImageTagsFlipHorizontal} +

Flip Vertical

+${changeFilesSymmetryImageTagsFlipVertical} +

Flip Diagonal

+${changeFilesSymmetryImageTagsFlipSlash} +

Rotate 180°

+${changeFilesSymmetryImageTagsRotate180} + +
Icons as code Works for: \`lucide-react\`, \`lucide-react-native\`, \`lucide-preact\`, \`lucide-vue-next\`