├── .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 |
3 |
4 |
5 | ## Tailwind CSS Image Mask Plugin
6 |
7 | [](https://badge.fury.io/js/@designbycode%2Ftailwindcss-mask-image)
8 | 
9 | 
10 | 
11 | 
12 | [](https://github.com/DesignByCode/tailwindcss-mask-image/stargazers)
13 | [](http://hits.dwyl.com/designbycode/tailwindcss-mask-image)
14 |
15 | [](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 | 
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 |