From fa274d11e0b984ec34688b1b9ffe0081d14c91dd Mon Sep 17 00:00:00 2001 From: rexdotsh <65942753+rexdotsh@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:39:50 +0530 Subject: [PATCH] feat: prettierc --- .prettierrc | 5 ++++ app.config.ts | 4 ++-- postcss.config.js | 2 +- src/app.css | 6 ++--- src/components/Art.tsx | 46 ++++++++++++++++++++++++++---------- src/components/MagicLink.tsx | 14 +++++++++-- src/entry-server.tsx | 10 ++++++-- 7 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..9482c5e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "useTabs": false, + "jsxBracketSameLine": true +} diff --git a/app.config.ts b/app.config.ts index e211630..55ceed6 100644 --- a/app.config.ts +++ b/app.config.ts @@ -1,8 +1,8 @@ -import {defineConfig} from "@solidjs/start/config"; +import { defineConfig } from "@solidjs/start/config"; /* @ts-ignore */ import pkg from "@vinxi/plugin-mdx"; -const {default: mdx} = pkg; +const { default: mdx } = pkg; export default defineConfig({ server: { baseURL: process.env.BASE_PATH, diff --git a/postcss.config.js b/postcss.config.js index 2e7af2b..2aa7205 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -3,4 +3,4 @@ export default { tailwindcss: {}, autoprefixer: {}, }, -} +}; diff --git a/src/app.css b/src/app.css index 66e8289..2f0d37a 100644 --- a/src/app.css +++ b/src/app.css @@ -9,15 +9,15 @@ } .link { - @apply text-neutral-400 hover:text-neutral-200 underline underline-offset-4 transition-colors duration-200; + @apply text-neutral-400 hover:text-neutral-200 underline underline-offset-4 transition-colors duration-200; } .retro { - background: repeating-linear-gradient( + background: repeating-linear-gradient( to bottom, #1c1c1c66, #1c1c1c66 1px, transparent 2px, transparent 6px ); -} \ No newline at end of file +} diff --git a/src/components/Art.tsx b/src/components/Art.tsx index 0997bd4..916912a 100644 --- a/src/components/Art.tsx +++ b/src/components/Art.tsx @@ -8,7 +8,12 @@ const AsciiArtConverter: Component = (props) => { const [ascii, setAscii] = createSignal(""); let canvasRef: HTMLCanvasElement | undefined; - const toGrayScale = (r: number, g: number, b: number, a: number): number | null => { + const toGrayScale = ( + r: number, + g: number, + b: number, + a: number + ): number | null => { // Return null for transparent pixels (alpha < 0.1) if (a < 25.5) { // 25.5 is 10% of 255 @@ -27,7 +32,11 @@ const AsciiArtConverter: Component = (props) => { return height / width; }; - const convertToGrayScales = (context: CanvasRenderingContext2D, width: number, height: number): (number | null)[] => { + const convertToGrayScales = ( + context: CanvasRenderingContext2D, + width: number, + height: number + ): (number | null)[] => { const imageData = context.getImageData(0, 0, width, height); const grayScales: (number | null)[] = []; @@ -39,7 +48,10 @@ const AsciiArtConverter: Component = (props) => { const grayScale = toGrayScale(r, g, b, a); if (grayScale !== null) { - imageData.data[i] = imageData.data[i + 1] = imageData.data[i + 2] = grayScale; + imageData.data[i] = + imageData.data[i + 1] = + imageData.data[i + 2] = + grayScale; } grayScales.push(grayScale); } @@ -54,17 +66,22 @@ const AsciiArtConverter: Component = (props) => { const clampDimensions = (width: number, height: number): [number, number] => { const rectifiedWidth = Math.floor(getFontRatio() * width); if (height > MAXIMUM_HEIGHT) { - const reducedWidth = Math.floor((rectifiedWidth * MAXIMUM_HEIGHT) / height); + const reducedWidth = Math.floor( + (rectifiedWidth * MAXIMUM_HEIGHT) / height + ); return [reducedWidth, MAXIMUM_HEIGHT]; } if (width > MAXIMUM_WIDTH) { - const reducedHeight = Math.floor((height * MAXIMUM_WIDTH) / rectifiedWidth); + const reducedHeight = Math.floor( + (height * MAXIMUM_WIDTH) / rectifiedWidth + ); return [MAXIMUM_WIDTH, reducedHeight]; } return [rectifiedWidth, height]; }; - const grayRamp = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\"^`'. "; + const grayRamp = + "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\"^`'. "; const rampLength = grayRamp.length; const getCharacterForGrayScale = (grayScale: number | null): string => { @@ -75,13 +92,16 @@ const AsciiArtConverter: Component = (props) => { }; const drawAscii = (grayScales: (number | null)[], width: number): void => { - const ascii = grayScales.reduce((asciiImage: string, grayScale: number | null, index: number) => { - let nextChars = getCharacterForGrayScale(grayScale); - if ((index + 1) % width === 0) { - nextChars += "\n"; - } - return asciiImage + nextChars; - }, ""); + const ascii = grayScales.reduce( + (asciiImage: string, grayScale: number | null, index: number) => { + let nextChars = getCharacterForGrayScale(grayScale); + if ((index + 1) % width === 0) { + nextChars += "\n"; + } + return asciiImage + nextChars; + }, + "" + ); setAscii(ascii); }; diff --git a/src/components/MagicLink.tsx b/src/components/MagicLink.tsx index bff587d..109b467 100644 --- a/src/components/MagicLink.tsx +++ b/src/components/MagicLink.tsx @@ -24,7 +24,12 @@ const MagicLink: Component = (props) => { return ( <> - setShowPreview(false)}> + setShowPreview(false)}> {props.children} @@ -39,7 +44,12 @@ const MagicLink: Component = (props) => { opacity: showPreview() ? "1" : "0", }}>
- Preview + Preview
diff --git a/src/entry-server.tsx b/src/entry-server.tsx index d8c9498..ca86777 100644 --- a/src/entry-server.tsx +++ b/src/entry-server.tsx @@ -17,13 +17,19 @@ export default createHandler(() => ( - + - +