├── .gitignore ├── .npmignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── CHANGELOG.md ├── LICENCE ├── README.md ├── banner.svg ├── dist ├── index.cjs └── index.umd.cjs ├── package.json ├── screenshot.png ├── src └── index.ts ├── tsconfig.json ├── utils └── converToPercentage.ts └── vite.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea* 3 | /node_modules 4 | .turbo -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .idea* 3 | /img* 4 | index.html 5 | mix-manifest.json 6 | .babelrc.json 7 | .eslintrc.json 8 | .gitignore 9 | /src* 10 | /test* 11 | .prettierrc 12 | babel.config.json 13 | gulpfile.js 14 | postcss-config.json 15 | tailwindcss.config.js 16 | tsconfig.json 17 | webpack.mix.js 18 | .turbo* 19 | esbuild.config.js 20 | 21 | *.jpeg 22 | *.jpg 23 | *.png 24 | *.svg 25 | README.md 26 | CHANGELOG.md 27 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | auto-install-peers=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | pnpm-debug.log* 6 | pnpm-error.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | coverage 10 | bower_components 11 | package.json 12 | package-lock.json 13 | node_modules/ 14 | .npm 15 | .pnpm 16 | .idea/ 17 | .DS_Store 18 | __tests__/* 19 | !__tests__/util/* 20 | examples/* 21 | !examples/**/*.config.js 22 | .run 23 | .editorconfig 24 | cache/ 25 | .github/ 26 | .eslintrc.json 27 | *.md 28 | .prettierrc -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": false, 5 | "singleQuote": false, 6 | "printWidth": 180, 7 | "useTabs": false, 8 | "singleLineLinkTags": false 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.0.0 4 | 5 | ### Added or Changed 6 | 7 | - Added this changelog :) -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Claude Myburgh @ DesignByCode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Title banner 3 | 4 | 5 | ## Tailwind CSS Image Mask Plugin 6 | 7 | [![npm version](https://badge.fury.io/js/@designbycode%2Ftailwindcss-mask-image.svg)](https://badge.fury.io/js/@designbycode%2Ftailwindcss-mask-image) 8 | ![npm](https://img.shields.io/npm/dt/%40designbycode/tailwindcss-mask-image) 9 | ![NPM](https://img.shields.io/npm/l/%40designbycode%2Ftailwindcss-mask-image) 10 | ![npm bundle size](https://img.shields.io/bundlephobia/min/%40designbycode%2Ftailwindcss-mask-image) 11 | ![ts](https://badgen.net/badge/Built%20With/TypeScript/blue) 12 | [![GitHub stars](https://img.shields.io/github/stars/DesignByCode/tailwindcss-mask-image?style=social)](https://github.com/DesignByCode/tailwindcss-mask-image/stargazers) 13 | [![HitCount](https://hits.dwyl.com/designbycode/tailwindcss-mask-image.svg?style=flat)](http://hits.dwyl.com/designbycode/tailwindcss-mask-image) 14 | 15 | [![NPM](https://nodei.co/npm/@designbycode/tailwindcss-mask-image.png)](https://nodei.co/npm/@designbycode/tailwindcss-mask-image/) 16 | 17 | The Tailwind CSS Image Mask Plugin is a custom plugin that extends Tailwind CSS with utilities for applying image masks using CSS gradients. With this plugin, you can easily create image masks with different directions and gradient styles. 18 | 19 | ![Mask Image Plugin](screenshot.png) 20 | 21 | ## 📇 Table of Contents 22 | 23 | * [Installation](#installation) 24 | * [Using pnpm](#using-pnpm) 25 | * [Using npm](#using-npm) 26 | * [Using yarn](#using-yarn) 27 | * [Usage](#usage) 28 | * [Utilities](#utilities) 29 | * [Applying Image Masks](#applying-image-masks) 30 | * [Default Values](#default-values) 31 | * [Changing Gradient Starting and Ending Points](#changing-gradient-starting-and-ending-points) 32 | * [Available percentage values for --mask-image-start and --mask-image-end:](#available-percentage-values-for---mask-image-start-and---mask-image-end) 33 | * [Configuration](#configuration) 34 | * [Example](#example) 35 | * [Contributing](#contributing) 36 | * [License](#license) 37 | * [Author](#author) 38 | * [Acknowledgments](#acknowledgments) 39 | 40 | ## Installation 41 | 42 | To use this plugin, you need to install it via pnpm, npm or yarn. 43 | 44 | #### Using pnpm 45 | 46 | ```bash 47 | pnpm add @designbycode/tailwindcss-mask-image 48 | ``` 49 | 50 | #### Using npm 51 | 52 | ```bash 53 | npm install @designbycode/tailwindcss-mask-image 54 | ``` 55 | 56 | #### Using yarn 57 | 58 | ```bash 59 | yarn add @designbycode/tailwindcss-mask-image 60 | ``` 61 | 62 | ## Usage 63 | 64 | Once the plugin is installed, you can enable it in your Tailwind CSS configuration file. Usually, this file is named tailwind.config.js. 65 | 66 | ```javascript 67 | module.exports = { 68 | // ...other configurations 69 | plugins: [ 70 | // ...other plugins 71 | require("@designbycode/tailwindcss-mask-image"), 72 | ], 73 | }; 74 | ``` 75 | 76 | ## Utilities 77 | 78 | The plugin generates several utility classes for applying image masks using CSS gradients. You can use these utility classes to easily apply masks to any element in your HTML. 79 | 80 | ## Applying Image Masks 81 | 82 | To make it work you only need to add the class of ```.mask-image-{value}``` to you html. The rest off the classes is just modifiers. 83 | 84 | ```html 85 | 86 |
87 | ``` 88 | 89 | You can apply image masks by using the following utility classes: 90 | 91 | | Css class name | Description | 92 | |:---------------|:----------------------------------------------| 93 | | .mask-image-t | Applies a mask from top to bottom. | 94 | | .mask-image-tr | Applies a mask from top left to bottom right. | 95 | | .mask-image-tl | Applies a mask from top right to bottom left. | 96 | | .mask-image-b | Applies a mask from bottom to top. | 97 | | .mask-image-br | Applies a mask from bottom left to top right. | 98 | | .mask-image-bl | Applies a mask from bottom right to top left. | 99 | | .mask-image-r | Applies a mask from left to right. | 100 | | .mask-image-l | Applies a mask from right to left. | 101 | 102 | ## Default Values 103 | 104 | The plugin sets some default CSS variables in the :root element, which define the default values for the color and direction of the image masks. 105 | 106 | | Css Variable | Description | 107 | |:---------------------------|:-----------------------------------------------| 108 | | --mask-image-start-{value} | Default gradient starting point (default: 0%) | 109 | | --mask-image-end-{value} | Default gradient ending point (default: 100%). | 110 | 111 | ## Changing Gradient Starting and Ending Points 112 | 113 | You can dynamically change the starting and ending points of the gradient using the following utility classes: 114 | 115 | * ```.mask-image-start-0``` to ```.mask-image-start-100```: Changes the --mask-image-start variable to the specified percentage value. 116 | 117 | * ```.mask-image-end-0 to``` ```.mask-image-end-100```: Changes the --mask-image-end variable to the specified percentage value. 118 | 119 | ```html 120 | 121 |
122 | 123 |
124 | ``` 125 | 126 | #### Available percentage values for --mask-image-start and --mask-image-end: 127 | 128 | | Key | Value | Output | 129 | |-----|:------:|:----------------------| 130 | | 0 | "0%" | .mask-image-start-0 | 131 | | 5 | "5%" | .mask-image-start-5 | 132 | | 10 | "10%" | .mask-image-start-10 | 133 | | 15 | "15%" | .mask-image-start-15 | 134 | | 20 | "20%" | .mask-image-start-20 | 135 | | 25 | "25%" | .mask-image-start-25 | 136 | | 30 | "30%" | .mask-image-start-30 | 137 | | 40 | "40%" | .mask-image-start-40 | 138 | | 45 | "45%" | .mask-image-start-45 | 139 | | 50 | "50%" | .mask-image-start-50 | 140 | | 55 | "55%" | .mask-image-start-55 | 141 | | 60 | "60%" | .mask-image-start-60 | 142 | | 70 | "70%" | .mask-image-start-70 | 143 | | 75 | "75%" | .mask-image-start-75 | 144 | | 80 | "80%" | .mask-image-start-80 | 145 | | 85 | "85%" | .mask-image-start-85 | 146 | | 90 | "90%" | .mask-image-start-90 | 147 | | 95 | "95%" | .mask-image-start-95 | 148 | | 100 | "100%" | .mask-image-start-100 | 149 | 150 | ## Configuration 151 | 152 | The plugin allows you to customize the gradient steps and directions by modifying the theme object in your Tailwind CSS configuration file. 153 | 154 | ```javascript 155 | // tailwind.config.js 156 | 157 | module.exports = { 158 | // ...other configurations 159 | plugins: [ 160 | // ...other plugins 161 | require("@designbycode/tailwindcss-mask-image"), 162 | ], 163 | theme: { 164 | imageMaskSteps: { 165 | // Add your custom gradient steps here 166 | 0: "0%", 167 | 10: "10%", 168 | 25: "25%", 169 | // ... 170 | }, 171 | imageMaskDirections: { 172 | // Add your custom mask directions here 173 | t: "to top", 174 | b: "to bottom", 175 | // ... 176 | }, 177 | }, 178 | }; 179 | 180 | ``` 181 | 182 | ## Example 183 | 184 | Here's an example of how you can use the utility classes to apply image masks: 185 | 186 | ```html 187 | 188 |
189 | 190 |
191 | 192 | ``` 193 | 194 | > **Note** 195 | > New to v2. 196 | > Start and end color opacity 197 | 198 | ### Opacity for start and end Color 199 | 200 | You can set the opacity for start and end color for more control over the mask. 201 | 202 | ```html 203 | 204 |
205 | 206 |
207 | ``` 208 | 209 | The arbitrary value have a range from 0 to 100 for even more control over the mask. 210 | 211 | ```html 212 | 213 |
214 | 215 |
216 | ``` 217 | 218 | ## Contributing 219 | 220 | Contributions to this plugin are welcome! If you encounter any issues, have feature requests, or want to improve the plugin, feel free to create a pull request or submit an issue on the GitHub repository. 221 | 222 | ## License 223 | 224 | This project is licensed under the [MIT](LICENCE) License - see the [LICENSE](LICENCE) file for details. 225 | 226 | ## Author 227 | 228 |
229 | Claude Myburgh 230 |
231 |

Claude Myburgh

233 | 234 | ## Acknowledgments 235 | 236 | - This plugin is inspired by the needs of web developers using Tailwind CSS. 237 | - Special thanks to the Tailwind CSS team for creating such an amazing framework. 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | -------------------------------------------------------------------------------- /banner.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 101 |
102 |

TailwindCSS Mask Image Plugin 103 |

104 |
105 | 🎉 106 | MADE FOR 107 | 🎉 108 |
109 |

Tailwindcss

110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /dist/index.cjs: -------------------------------------------------------------------------------- 1 | "use strict";const a=require("tailwindcss/plugin");module.exports=a.withOptions((function(){return function({addBase:a,matchUtilities:t,theme:i}){a({":root":{"--mi-mask-image-start-opacity":"rgba(0,0,0,1)","--mi-mask-image-end-opacity":"rgba(0,0,0,0)","--mi-mask-image-direction":"to bottom","--mi-mask-image-start":"0%","--mi-mask-image-end":"100%"}}),t({"mask-image":a=>({maskImage:`linear-gradient(${a}, var(--mi-mask-image-start-opacity) var(--mi-mask-image-start), var(--mi-mask-image-end-opacity) var(--mi-mask-image-end))`})},{values:i("imageMaskDirections"),type:["any"]}),t({"mask-image-start":a=>({"--mi-mask-image-start":a}),"mask-image-end":a=>({"--mi-mask-image-end":a})},{values:i("imageMaskSteps"),type:"length"}),t({"mask-image-start-opacity":a=>({"--mi-mask-image-start-opacity":`rgba(0,0,0, ${a})`}),"mask-image-end-opacity":a=>({"--mi-mask-image-end-opacity":`rgba(0,0,0, ${a})`})},{values:i("opacity")})}}),(function(){return{theme:{imageMaskSteps:{0:"0%",5:"5%",10:"10%",15:"15%",20:"20%",25:"25%",30:"30%",40:"40%",45:"45%",50:"50%",55:"55%",60:"60%",70:"70%",75:"75%",80:"80%",85:"85%",90:"90%",95:"95%",100:"100%"},imageMaskDirections:{t:"to top",tr:"to top right",tl:"to top left",b:"to bottom",br:"to bottom right",bl:"to bottom left",r:"to right",l:"to left"}}}})); 2 | -------------------------------------------------------------------------------- /dist/index.umd.cjs: -------------------------------------------------------------------------------- 1 | !function(t){"function"==typeof define&&define.amd?define(t):t()}((function(){"use strict";const t=require("tailwindcss/plugin");module.exports=t.withOptions((function(){return function({addBase:t,matchUtilities:a,theme:i}){t({":root":{"--mi-mask-image-start-opacity":"rgba(0,0,0,1)","--mi-mask-image-end-opacity":"rgba(0,0,0,0)","--mi-mask-image-direction":"to bottom","--mi-mask-image-start":"0%","--mi-mask-image-end":"100%"}}),a({"mask-image":t=>({maskImage:`linear-gradient(${t}, var(--mi-mask-image-start-opacity) var(--mi-mask-image-start), var(--mi-mask-image-end-opacity) var(--mi-mask-image-end))`})},{values:i("imageMaskDirections"),type:["any"]}),a({"mask-image-start":t=>({"--mi-mask-image-start":t}),"mask-image-end":t=>({"--mi-mask-image-end":t})},{values:i("imageMaskSteps"),type:"length"}),a({"mask-image-start-opacity":t=>({"--mi-mask-image-start-opacity":`rgba(0,0,0, ${t})`}),"mask-image-end-opacity":t=>({"--mi-mask-image-end-opacity":`rgba(0,0,0, ${t})`})},{values:i("opacity")})}}),(function(){return{theme:{imageMaskSteps:{0:"0%",5:"5%",10:"10%",15:"15%",20:"20%",25:"25%",30:"30%",40:"40%",45:"45%",50:"50%",55:"55%",60:"60%",70:"70%",75:"75%",80:"80%",85:"85%",90:"90%",95:"95%",100:"100%"},imageMaskDirections:{t:"to top",tr:"to top right",tl:"to top left",b:"to bottom",br:"to bottom right",bl:"to bottom left",r:"to right",l:"to left"}}}}))})); 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@designbycode/tailwindcss-mask-image", 3 | "version": "2.0.2", 4 | "description": "Tailwindcss utilities for text stroke", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/DesignByCode/tailwindcss-mask-image.git" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/DesignByCode/tailwindcss-mask-image/issues" 12 | }, 13 | "homepage": "https://github.com/DesignByCode/tailwindcss-mask-image#readme", 14 | "authors": [ 15 | { 16 | "name": "Claude Myburgh", 17 | "email": "claude@designbycode.co.za", 18 | "url": "https://designbycode.co.za" 19 | } 20 | ], 21 | "licenses": [ 22 | { 23 | "type": "MIT", 24 | "url": "https://github.com/DesignByCode/tailwindcss-mask-image/blob/main/LICENCE" 25 | } 26 | ], 27 | "keywords": [ 28 | "front-end", 29 | "frontend", 30 | "css", 31 | "tailwindcss", 32 | "gradient mask", 33 | "plugin", 34 | "tailwindcss-plugin", 35 | "tailwindcss mask-image", 36 | "mask image", 37 | "designbycode" 38 | ], 39 | "type": "module", 40 | "files": [ 41 | "dist", 42 | "utils" 43 | ], 44 | "main": "./dist/index.umd.cjs", 45 | "module": "./dist/index.js", 46 | "exports": { 47 | ".": { 48 | "import": "./dist/index.js", 49 | "require": "./dist/index.umd.cjs" 50 | } 51 | }, 52 | "publishConfig": { 53 | "access": "public" 54 | }, 55 | "scripts": { 56 | "build": "tsc && vite build", 57 | "clean": "rd /s /q dist .cache>nul 2>&1|echo.>nul", 58 | "dev": "pnpm build --watch", 59 | "postbuild": "tsc --emitDeclarationOnly", 60 | "prepublishOnly": "pnpm build" 61 | }, 62 | "lint-staged": { 63 | "src/**/*.ts": [ 64 | "prettier --write", 65 | "git add" 66 | ] 67 | }, 68 | "browserslist": [ 69 | "> .5% or last 2 versions" 70 | ], 71 | "peerDependencies": { 72 | "tailwindcss": ">=3.0.0 || >=3.0.0-alpha.1" 73 | }, 74 | "devDependencies": { 75 | "@types/node": "^20.4.8", 76 | "autoprefixer": "^10.4.14", 77 | "husky": "^8.0.3", 78 | "postcss": "^8.4.27", 79 | "prettier": "^2.8.8", 80 | "tailwindcss": "^3.3.3", 81 | "terser": "^5.19.2", 82 | "typescript": "^5.0.2", 83 | "vite": "^4.4.5", 84 | "vite-plugin-dts": "^3.5.1" 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/designbycode/tailwindcss-mask-image/dfb107447441323ce2a0d4ee07d86d5b18e3ca15/screenshot.png -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | const plugin = require("tailwindcss/plugin") 2 | 3 | module.exports = plugin.withOptions( 4 | function () { 5 | return function ({ addBase, matchUtilities, theme }: any) { 6 | // Default values 7 | addBase({ 8 | ":root": { 9 | "--mi-mask-image-start-opacity": "rgba(0,0,0,1)", 10 | "--mi-mask-image-end-opacity": "rgba(0,0,0,0)", 11 | "--mi-mask-image-direction": "to bottom", 12 | "--mi-mask-image-start": "0%", 13 | "--mi-mask-image-end": "100%", 14 | }, 15 | }) 16 | 17 | matchUtilities( 18 | { 19 | // Function to generate the CSS properties based on the value from the theme 20 | "mask-image": (value: string) => ({ 21 | maskImage: `linear-gradient(${value}, var(--mi-mask-image-start-opacity) var(--mi-mask-image-start), var(--mi-mask-image-end-opacity) var(--mi-mask-image-end))`, 22 | }), 23 | }, 24 | { 25 | // Specify the theme object that contains the image mask directions 26 | values: theme("imageMaskDirections"), 27 | type: ["any"], 28 | } 29 | ) 30 | 31 | // Dynamically changes value form arbitrary values and generate utility classes from theme imageMaskSteps object 32 | matchUtilities( 33 | { 34 | "mask-image-start": (value: string) => ({ 35 | "--mi-mask-image-start": value, 36 | }), 37 | 38 | "mask-image-end": (value: string) => ({ 39 | "--mi-mask-image-end": value, 40 | }), 41 | }, 42 | { 43 | values: theme("imageMaskSteps"), 44 | type: "length", 45 | } 46 | ) 47 | 48 | matchUtilities( 49 | { 50 | "mask-image-start-opacity": (value: string) => { 51 | return { 52 | "--mi-mask-image-start-opacity": `rgba(0,0,0, ${value})`, 53 | } 54 | }, 55 | 56 | "mask-image-end-opacity": (value: string) => { 57 | return { 58 | "--mi-mask-image-end-opacity": `rgba(0,0,0, ${value})`, 59 | } 60 | }, 61 | }, 62 | { 63 | values: theme("opacity"), 64 | } 65 | ) 66 | } 67 | }, 68 | function () { 69 | return { 70 | theme: { 71 | imageMaskSteps: { 72 | 0: "0%", 73 | 5: "5%", 74 | 10: "10%", 75 | 15: "15%", 76 | 20: "20%", 77 | 25: "25%", 78 | 30: "30%", 79 | 40: "40%", 80 | 45: "45%", 81 | 50: "50%", 82 | 55: "55%", 83 | 60: "60%", 84 | 70: "70%", 85 | 75: "75%", 86 | 80: "80%", 87 | 85: "85%", 88 | 90: "90%", 89 | 95: "95%", 90 | 100: "100%", 91 | }, 92 | /** 93 | * @type {{br: string, r: string, b: string, t: string, tl: string, bl: string, l: string, tr: string}} 94 | */ 95 | imageMaskDirections: { 96 | t: "to top", 97 | tr: "to top right", 98 | tl: "to top left", 99 | b: "to bottom", 100 | br: "to bottom right", 101 | bl: "to bottom left", 102 | r: "to right", 103 | l: "to left", 104 | }, 105 | }, 106 | } 107 | } 108 | ) 109 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": [ 7 | "ES2020", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "skipLibCheck": true, 12 | /* Bundler mode */ 13 | "moduleResolution": "node", 14 | "allowImportingTsExtensions": true, 15 | "resolveJsonModule": true, 16 | "isolatedModules": true, 17 | "noEmit": true, 18 | /* Linting */ 19 | "strict": true, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "noFallthroughCasesInSwitch": true, 23 | "declaration": true, 24 | "removeComments": true, 25 | "sourceMap": true 26 | }, 27 | "include": [ 28 | "src" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /utils/converToPercentage.ts: -------------------------------------------------------------------------------- 1 | export default function convertToPercentage(value: number): string { 2 | value = value / 100 3 | return Math.abs(Math.min(value, 1)).toString() 4 | } 5 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | // vite.config.js 2 | import { resolve } from "path" 3 | import { defineConfig } from "vite" 4 | 5 | export default defineConfig({ 6 | build: { 7 | lib: { 8 | // Could also be a dictionary or array of multiple entry points 9 | entry: resolve(__dirname, "src/index.ts"), 10 | name: "Tailwindcss Mask Image", 11 | // the proper extensions will be added 12 | fileName: "index", 13 | formats: ["cjs", "umd"], 14 | }, 15 | minify: "terser", 16 | }, 17 | // plugins: [dts()], 18 | }) 19 | --------------------------------------------------------------------------------