diff --git a/README.md b/README.md index 84e8946..e86265f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A `mask-image` plugin for [Tailwind CSS](https://tailwindcss.com). -[View on Tailwind Play](https://play.tailwindcss.com/5nqePqTxTt) +[View on Tailwind Play](https://play.tailwindcss.com/LF91xWKHl7) --- @@ -73,6 +73,17 @@ The `opacity` values are taken from your theme specified in the `tailwind.config > **Note** > You don't have to specify **all** the stops, because the default values (100% for the start and 0% for the end point) still work. +##### Stops positions + +In addition to setting the opacity of the stops, you can also set the **position** using `mask-point`. + +```html +
+
+``` +![stops' points example](examples/mask-linear-stops-points.png) + +This utility don't accept any default value, so use arbitrary values. ### `radial` @@ -129,11 +140,12 @@ You can also use arbitrary values: #### Stops > **Note** -> The opacity stops are the same as [the ones described for `mask-linear`](#opacity-stops). +> The opacity stops for `mask-radial` are the same as [the ones described for `mask-linear`](#opacity-stops), including [points API](#stops-positions). ```html
+
``` ![mask-radial stops' example](examples/mask-radial-stops.png) diff --git a/examples/arbitary-conic-gradient.png b/examples/arbitrary-conic-gradient.png similarity index 100% rename from examples/arbitary-conic-gradient.png rename to examples/arbitrary-conic-gradient.png diff --git a/examples/arbitary-image.png b/examples/arbitrary-image.png similarity index 100% rename from examples/arbitary-image.png rename to examples/arbitrary-image.png diff --git a/examples/mask-linear-stops-points.png b/examples/mask-linear-stops-points.png new file mode 100644 index 0000000..1f587a1 Binary files /dev/null and b/examples/mask-linear-stops-points.png differ diff --git a/examples/mask-radial-stops.png b/examples/mask-radial-stops.png index 01d0c93..31cef34 100644 Binary files a/examples/mask-radial-stops.png and b/examples/mask-radial-stops.png differ diff --git a/examples/mask-size-arbitary.png b/examples/mask-size-arbitrary.png similarity index 100% rename from examples/mask-size-arbitary.png rename to examples/mask-size-arbitrary.png diff --git a/index.js b/index.js index 1c5aa75..f4d672f 100644 --- a/index.js +++ b/index.js @@ -22,9 +22,11 @@ module.exports = plugin(({ theme, addUtilities, matchUtilities }) => { // stops '--tw-mask-from-opacity': '1', - '--tw-mask-from': 'rgba(0,0,0,var(--tw-mask-from-opacity))', + '--tw-mask-point-from': '', + '--tw-mask-from': 'rgba(0,0,0,var(--tw-mask-from-opacity)) var(--tw-mask-point-from)', '--tw-mask-to-opacity': '0', - '--tw-mask-to': 'rgba(0,0,0,var(--tw-mask-to-opacity))', + '--tw-mask-point-to': '', + '--tw-mask-to': 'rgba(0,0,0,var(--tw-mask-to-opacity)) var(--tw-mask-point-to)', '--tw-mask-stops': 'var(--tw-mask-from), var(--tw-mask-to)', }), }, @@ -124,7 +126,7 @@ module.exports = plugin(({ theme, addUtilities, matchUtilities }) => { } ) - // - stops + // - stops' colors // NOTE: Can accept custom opacity as an arbitrary value, e.g. `mask-dir-[0.25]` matchUtilities( { @@ -135,9 +137,23 @@ module.exports = plugin(({ theme, addUtilities, matchUtilities }) => { '--tw-mask-to-opacity': value, }), 'mask-via': (value) => ({ - '--tw-mask-stops': `var(--tw-mask-from), rgba(0,0,0,${value}), var(--tw-mask-to)`, + '--tw-mask-point-via': '', + '--tw-mask-stops': `var(--tw-mask-from), rgba(0,0,0,${value}) var(--tw-mask-point-via), var(--tw-mask-to)`, }), }, { values: theme('opacity') } ) + + // - stops' points + matchUtilities({ + 'mask-point-from': (value) => ({ + '--tw-mask-point-from': value, + }), + 'mask-point-to': (value) => ({ + '--tw-mask-point-to': value, + }), + 'mask-point-via': (value) => ({ + '--tw-mask-point-via': value, + }), + }) }) diff --git a/playground/README.md b/playground/README.md index 9724e85..767ac55 100644 --- a/playground/README.md +++ b/playground/README.md @@ -3,4 +3,4 @@ You can past them in the [Tailwind Play](https://play.tailwindcss.com) and have > The shared playground is here: > -> [View on Tailwind Play](https://play.tailwindcss.com/5nqePqTxTt) +> [View on Tailwind Play](https://play.tailwindcss.com/LF91xWKHl7) diff --git a/playground/index.html b/playground/index.html index bb23b1a..f20bfef 100644 --- a/playground/index.html +++ b/playground/index.html @@ -30,6 +30,15 @@

Linear

+
+
+
+
+
+
+
+
+

Radial

@@ -78,6 +87,9 @@

Radial

+
+
+

None

diff --git a/playground/tailwind.config.js b/playground/tailwind.config.js index 00e1da2..9fad5f0 100644 --- a/playground/tailwind.config.js +++ b/playground/tailwind.config.js @@ -9,25 +9,28 @@ module.exports = { { mask: (value) => ({ maskImage: value, - + maskRepeat: 'var(--tw-mask-repeat)', + /** * Default vars */ '--tw-mask-repeat': 'repeat', - + // linear-gradient props '--tw-mask-direction': 'to bottom', - + // radial-gradient props '--tw-mask-shape': '', '--tw-mask-size': 'closest-side', '--tw-mask-at': 'center', - + // stops '--tw-mask-from-opacity': '1', - '--tw-mask-from': 'rgba(0,0,0,var(--tw-mask-from-opacity))', + '--tw-mask-point-from': '', + '--tw-mask-from': 'rgba(0,0,0,var(--tw-mask-from-opacity)) var(--tw-mask-point-from)', '--tw-mask-to-opacity': '0', - '--tw-mask-to': 'rgba(0,0,0,var(--tw-mask-to-opacity))', + '--tw-mask-point-to': '', + '--tw-mask-to': 'rgba(0,0,0,var(--tw-mask-to-opacity)) var(--tw-mask-point-to)', '--tw-mask-stops': 'var(--tw-mask-from), var(--tw-mask-to)', }), }, @@ -40,7 +43,7 @@ module.exports = { }, } ) - + addUtilities({ '.mask-repeat': { maskRepeat: 'repeat', @@ -49,7 +52,7 @@ module.exports = { maskRepeat: 'no-repeat', }, }) - + // - direction // NOTE: Can accept angle as an arbitrary value, e.g. `mask-dir-[30deg]` matchUtilities( @@ -71,7 +74,7 @@ module.exports = { }, } ) - + // - shape addUtilities({ '.mask-shape-circle': { @@ -81,7 +84,7 @@ module.exports = { '--tw-mask-shape': 'ellipse', }, }) - + // - size // NOTE: Can accept X Y size as an arbitrary value, e.g. `mask-size-[25%_25%]` matchUtilities( @@ -98,12 +101,12 @@ module.exports = { 'farthest-side': 'farthest-side', 'farthest-corner': 'farthest-corner', // aliases - contain: 'closest-side', - cover: 'farthest-corner', + 'contain': 'closest-side', + 'cover': 'farthest-corner', }, - } + }, ) - + // - position // NOTE: Can accept X Y position as an arbitrary value, e.g. `mask-at-[50%_10px]` matchUtilities( @@ -126,8 +129,8 @@ module.exports = { }, } ) - - // - stops + + // - stops' colors // NOTE: Can accept custom opacity as an arbitrary value, e.g. `mask-dir-[0.25]` matchUtilities( { @@ -138,11 +141,25 @@ module.exports = { '--tw-mask-to-opacity': value, }), 'mask-via': (value) => ({ - '--tw-mask-stops': `var(--tw-mask-from), rgba(0,0,0,${value}), var(--tw-mask-to)`, + '--tw-mask-point-via': '', + '--tw-mask-stops': `var(--tw-mask-from), rgba(0,0,0,${value}) var(--tw-mask-point-via), var(--tw-mask-to)`, }), }, { values: theme('opacity') } ) + + // - stops' points + matchUtilities({ + 'mask-point-from': (value) => ({ + '--tw-mask-point-from': value, + }), + 'mask-point-to': (value) => ({ + '--tw-mask-point-to': value, + }), + 'mask-point-via': (value) => ({ + '--tw-mask-point-via': value, + }), + }) }, // helper