Repository: phamfoo/figma-squircle Branch: main Commit: 45622dc2e9b2 Files: 24 Total size: 26.6 KB Directory structure: gitextract_bvuf0zy_/ ├── .gitignore ├── LICENSE ├── README.md ├── eslint.config.js ├── package.json ├── prettier.config.js ├── site/ │ ├── .gitignore │ ├── index.html │ ├── package.json │ ├── postcss.config.js │ ├── src/ │ │ ├── App.tsx │ │ ├── app.css │ │ ├── index.css │ │ ├── main.tsx │ │ └── vite-env.d.ts │ ├── tailwind.config.js │ ├── tsconfig.app.json │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.ts ├── src/ │ ├── distribute.ts │ ├── draw.ts │ └── index.ts └── tsconfig.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # dependencies node_modules .pnp .pnp.js # testing coverage # next.js .next/ out/ build # misc .DS_Store *.pem # debug npm-debug.log* yarn-debug.log* yarn-error.log* .pnpm-debug.log* # local env files .env.local .env.development.local .env.test.local .env.production.local # turbo .turbo #parcel .parcel-cache # build dist/ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2021 Tien Pham Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Figma Squircle [![Stable Release](https://img.shields.io/npm/v/figma-squircle)](https://npm.im/figma-squircle) [![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE) > Figma-flavored squircles for everyone ## Disclaimer > This library is not an official product from the Figma team and does not guarantee to produce the same results as you would get in Figma. ## What is this? Figma has a great feature called [corner smoothing](https://help.figma.com/hc/en-us/articles/360050986854-Adjust-corner-radius-and-smoothing), allowing you to create rounded shapes with a seamless continuous curve (squircles). ![](squircle.jpg) This library helps you bring those squircles to your apps. ## Installation ```sh npm install figma-squircle ``` ## Usage ```jsx import { getSvgPath } from 'figma-squircle' const svgPath = getSvgPath({ width: 200, height: 200, cornerRadius: 24, // defaults to 0 cornerSmoothing: 0.8, // cornerSmoothing goes from 0 to 1 }) const svgPath = getSvgPath({ width: 200, height: 200, cornerRadius: 24, cornerSmoothing: 0.8, // You can also adjust the radius of each corner individually topLeftCornerRadius: 48, }) // svgPath can now be used to create SVG elements function PinkSquircle() { return ( ) } // Or with the clip-path CSS property function ProfilePicture() { return (
...
) } ``` ## Preserve Smoothing The larger the corner radius, the less space we have left to make a smooth transition from the straight line to the rounded corner. As a result, you might have noticed that the smoothing effect appears to be less pronounced as the radius gets bigger. Try enabling `preserveSmoothing` if you're not happy with the generated shape. ```jsx const svgPath = getSvgPath({ width: 200, height: 200, cornerRadius: 80, cornerSmoothing: 0.8, preserveSmoothing: true, // defaults to false }) ``` There's also a [Figma plugin](https://www.figma.com/community/plugin/1122437229616103296) that utilizes this option. ## Thanks - Figma team for publishing [this article](https://www.figma.com/blog/desperately-seeking-squircles/) and [MartinRGB](https://github.com/MartinRGB) for [figuring out all the math](https://github.com/MartinRGB/Figma_Squircles_Approximation) behind it. - [George Francis](https://github.com/georgedoescode) for creating [Squircley](https://squircley.app/), which was my introduction to squircles. ## Related - https://github.com/phamfoo/react-native-figma-squircle ================================================ FILE: eslint.config.js ================================================ import pluginJs from '@eslint/js' import tseslint from 'typescript-eslint' export default [ { ignores: ['dist/'] }, pluginJs.configs.recommended, ...tseslint.configs.recommended, ] ================================================ FILE: package.json ================================================ { "name": "figma-squircle", "description": "Figma-flavored squircles for everyone", "type": "module", "author": "Tien Pham", "version": "1.1.0", "license": "MIT", "source": "src/index.ts", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { "lint": "eslint", "build": "tsup src/index.ts --format esm --dts", "prepare": "npm run build" }, "devDependencies": { "@eslint/js": "^9.9.1", "eslint": "^9.9.1", "prettier": "^3.3.3", "tsup": "^8.3.0", "typescript": "^5.5.4", "typescript-eslint": "^8.3.0" }, "files": [ "dist", "src" ], "keywords": [ "squircle", "react", "figma" ], "repository": { "type": "git", "url": "https://github.com/phamfoo/figma-squircle.git" } } ================================================ FILE: prettier.config.js ================================================ export default { singleQuote: true, tabWidth: 2, trailingComma: 'es5', useTabs: false, semi: false, } ================================================ FILE: site/.gitignore ================================================ # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* pnpm-debug.log* lerna-debug.log* node_modules dist dist-ssr *.local # Editor directories and files .vscode/* !.vscode/extensions.json .idea .DS_Store *.suo *.ntvs* *.njsproj *.sln *.sw? ================================================ FILE: site/index.html ================================================ Figma Squircle
================================================ FILE: site/package.json ================================================ { "name": "site2", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", "build": "tsc -b && vite build", "preview": "vite preview" }, "dependencies": { "figma-squircle": "file:..", "preact": "^10.23.1" }, "devDependencies": { "@preact/preset-vite": "^2.9.0", "autoprefixer": "^10.4.20", "postcss": "^8.4.45", "tailwindcss": "^3.4.10", "typescript": "^5.5.3", "vite": "^5.4.1" } } ================================================ FILE: site/postcss.config.js ================================================ export default { plugins: { tailwindcss: {}, autoprefixer: {}, }, } ================================================ FILE: site/src/App.tsx ================================================ import { useEffect, useState } from 'preact/hooks' import './app.css' import { getSvgPath } from 'figma-squircle' import sizeIcon from './assets/size.svg' import radiusIcon from './assets/radius.svg' export function App() { const [size, setSize] = useState(400) const [cornerRadius, setCornerRadius] = useState(120) const [cornerSmoothingPercent, setCornerSmoothingPercent] = useState(60) const [preserveSmoothing, setPreserveSmoothing] = useState(false) const svgPath = getSvgPath({ width: size, height: size, cornerRadius, cornerSmoothing: cornerSmoothingPercent / 100, preserveSmoothing, }) return (
) } interface NumberInputProps { label: string icon: string value: number onChange: (value: number) => void } function NumberInput({ label, icon, value, onChange }: NumberInputProps) { return ( ) } interface IconSliderProps { value: number onChange: (value: number) => void icon: string } // https://dev.to/graftini/how-to-change-numeric-input-by-dragging-in-react-315 function IconSlider({ value, onChange, icon }: IconSliderProps) { const [initialX, setInitialX] = useState(null) const [snapshot, setSnapshot] = useState(value) useEffect(() => { function onUpdate(event: MouseEvent) { if (initialX !== null) { onChange(snapshot + event.clientX - initialX) } } function onEnd() { setInitialX(null) } document.addEventListener('mousemove', onUpdate) document.addEventListener('mouseup', onEnd) return () => { document.removeEventListener('mousemove', onUpdate) document.removeEventListener('mouseup', onEnd) } }, [initialX, onChange, snapshot]) return (
{ setInitialX(e.clientX) setSnapshot(value) }} >
) } interface PreserveSmoothingToggleProps { value: boolean onChange: (value: boolean) => void } function PreserveSmoothingToggle({ value, onChange, }: PreserveSmoothingToggleProps) { return (