createUtilityPlugin.js 1.9 KB

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