You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.8 KiB

2 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "default", {
  6. enumerable: true,
  7. get: ()=>createUtilityPlugin
  8. });
  9. const _transformThemeValue = /*#__PURE__*/ _interopRequireDefault(require("./transformThemeValue"));
  10. function _interopRequireDefault(obj) {
  11. return obj && obj.__esModule ? obj : {
  12. default: obj
  13. };
  14. }
  15. function createUtilityPlugin(themeKey, utilityVariations = [
  16. [
  17. themeKey,
  18. [
  19. themeKey
  20. ]
  21. ]
  22. ], { filterDefault =false , ...options } = {}) {
  23. let transformValue = (0, _transformThemeValue.default)(themeKey);
  24. return function({ matchUtilities , theme }) {
  25. for (let utilityVariation of utilityVariations){
  26. let group = Array.isArray(utilityVariation[0]) ? utilityVariation : [
  27. utilityVariation
  28. ];
  29. var ref;
  30. matchUtilities(group.reduce((obj, [classPrefix, properties])=>{
  31. return Object.assign(obj, {
  32. [classPrefix]: (value)=>{
  33. return properties.reduce((obj, name)=>{
  34. if (Array.isArray(name)) {
  35. return Object.assign(obj, {
  36. [name[0]]: name[1]
  37. });
  38. }
  39. return Object.assign(obj, {
  40. [name]: transformValue(value)
  41. });
  42. }, {});
  43. }
  44. });
  45. }, {}), {
  46. ...options,
  47. values: filterDefault ? Object.fromEntries(Object.entries((ref = theme(themeKey)) !== null && ref !== void 0 ? ref : {}).filter(([modifier])=>modifier !== "DEFAULT")) : theme(themeKey)
  48. });
  49. }
  50. };
  51. }