|
1 | | -const plugin = require('tailwindcss/plugin') |
| 1 | +const plugin = require("tailwindcss/plugin"); |
2 | 2 |
|
3 | | -module.exports = plugin(function({ addUtilities, e }) { |
4 | | - addUtilities({ |
5 | | - [`.${e('?')}`]: { |
6 | | - 'outline-style': 'solid', |
7 | | - 'animation': `${e('?')}wobble 0.6s ease-in-out alternate infinite` |
8 | | - }, |
9 | | - [`@keyframes ${e('?')}wobble`]: { |
10 | | - '0%': { |
11 | | - 'outline-width': '4px', |
12 | | - 'outline-color': '#f16bc9', |
13 | | - 'box-shadow': 'inset 4px 4px #f16bc9, inset -4px -4px #f16bc9' |
14 | | - }, |
15 | | - '100%': { |
16 | | - 'outline-width': '6px', |
17 | | - 'outline-color': '#f71fb6', |
18 | | - 'box-shadow': 'inset 6px 6px #f71fb6, inset -6px -6px #f71fb6' |
19 | | - }, |
20 | | - } |
21 | | - }); |
22 | | -}); |
| 3 | +function parsePx(input, defaultValue) { |
| 4 | + let value = input.match(/\d+px/); |
| 5 | + if (value) { |
| 6 | + return parseInt(value[0], 10); |
| 7 | + } |
| 8 | + return defaultValue; |
| 9 | +} |
| 10 | + |
| 11 | +module.exports = plugin.withOptions( |
| 12 | + ({ |
| 13 | + animationDuration = "0.6s", |
| 14 | + enableAnimation = true, |
| 15 | + highlightColorStart = "#f16bc9", |
| 16 | + highlightColorEnd = "#f71fb6", |
| 17 | + widthStart = "8px", |
| 18 | + widthEnd = "12px", |
| 19 | + } = {}) => { |
| 20 | + return function ({ addUtilities, e }) { |
| 21 | + const ANIMATION_NAME = "wobble"; |
| 22 | + const OUTLINE_STYLE = "solid"; |
| 23 | + |
| 24 | + const widthStartPx = `${parsePx(widthStart, 8) / 2}px`; |
| 25 | + const widthEndPx = `${parsePx(widthEnd, 12) / 2}px`; |
| 26 | + |
| 27 | + const boxShadowStart = `inset ${widthStartPx} ${widthStartPx} ${highlightColorStart}, inset -${widthStartPx} -${widthStartPx} ${highlightColorStart}`; |
| 28 | + const boxShadowEnd = `inset ${widthEndPx} ${widthEndPx} ${highlightColorEnd}, inset -${widthEndPx} -${widthEndPx} ${highlightColorEnd}`; |
| 29 | + |
| 30 | + const animation = enableAnimation |
| 31 | + ? `${e( |
| 32 | + "?" |
| 33 | + )}${ANIMATION_NAME} ${animationDuration} ease-in-out alternate infinite` |
| 34 | + : "none"; |
| 35 | + |
| 36 | + addUtilities({ |
| 37 | + [`.${e("?")}`]: { |
| 38 | + "outline-style": OUTLINE_STYLE, |
| 39 | + "outline-width": widthStartPx, |
| 40 | + "outline-color": highlightColorStart, |
| 41 | + "box-shadow": boxShadowStart, |
| 42 | + animation: animation, |
| 43 | + }, |
| 44 | + [`@keyframes ${e("?")}${ANIMATION_NAME}`]: { |
| 45 | + "0%": { |
| 46 | + "outline-width": widthStartPx, |
| 47 | + "outline-color": highlightColorStart, |
| 48 | + "box-shadow": boxShadowStart, |
| 49 | + }, |
| 50 | + "100%": { |
| 51 | + "outline-width": widthEndPx, |
| 52 | + "outline-color": highlightColorEnd, |
| 53 | + "box-shadow": boxShadowEnd, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }); |
| 57 | + }; |
| 58 | + } |
| 59 | +); |
0 commit comments