|
| 1 | +"use strict"; |
| 2 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 3 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 4 | +}; |
| 5 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 6 | +const plugin_1 = __importDefault(require("tailwindcss/plugin")); |
| 7 | +module.exports = plugin_1.default.withOptions(function (options = {}) { |
| 8 | + return function ({ matchUtilities, theme, config }) { |
| 9 | + const context = { |
| 10 | + theme, |
| 11 | + config, |
| 12 | + ...(options !== null && options !== void 0 ? options : {}), |
| 13 | + }; |
| 14 | + matchUtilities({ |
| 15 | + js: (value) => { |
| 16 | + const escape = (str) => { |
| 17 | + console.log(`escaping \`${str}\``); |
| 18 | + return str.replace(/_/g, '\\_').replace(/ /g, '_'); |
| 19 | + }; |
| 20 | + const unescape = (str) => { |
| 21 | + console.log(`unescaping \`${str}\``); |
| 22 | + str = str.replace(/(?<!\\)_/g, ' '); |
| 23 | + str = str.replace(/\\_/g, '_'); |
| 24 | + return str; |
| 25 | + }; |
| 26 | + const parseString = (str) => { |
| 27 | + console.log(`parsing \`${str}\``); |
| 28 | + return str.split(/(#{.*?})/g).map((el, i) => (i % 2 === 1 ? el.slice(2, -1) : el)); |
| 29 | + }; |
| 30 | + const parts = parseString(escape(value)); |
| 31 | + const utility = parts |
| 32 | + .map((part, i) => { |
| 33 | + if (i % 2 === 0) { |
| 34 | + return part; |
| 35 | + } |
| 36 | + else { |
| 37 | + const args = Object.keys(context); |
| 38 | + const values = Object.values(context); |
| 39 | + const func = new Function(...args, `return ${unescape(part)};`); |
| 40 | + return escape(`${func(...values)}`); |
| 41 | + } |
| 42 | + }) |
| 43 | + .join(''); |
| 44 | + return { |
| 45 | + [`@apply ${utility}`]: {}, |
| 46 | + }; |
| 47 | + }, |
| 48 | + }); |
| 49 | + }; |
| 50 | +}); |
0 commit comments