UNPKG

2.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", {
3 value: true
4});
5Object.defineProperty(exports, "default", {
6 enumerable: true,
7 get: ()=>transformThemeValue
8});
9const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
10const _isPlainObject = /*#__PURE__*/ _interopRequireDefault(require("./isPlainObject"));
11function _interopRequireDefault(obj) {
12 return obj && obj.__esModule ? obj : {
13 default: obj
14 };
15}
16function transformThemeValue(themeSection) {
17 if ([
18 "fontSize",
19 "outline"
20 ].includes(themeSection)) {
21 return (value)=>{
22 if (typeof value === "function") value = value({});
23 if (Array.isArray(value)) value = value[0];
24 return value;
25 };
26 }
27 if (themeSection === "fontFamily") {
28 return (value)=>{
29 if (typeof value === "function") value = value({});
30 let families = Array.isArray(value) && (0, _isPlainObject.default)(value[1]) ? value[0] : value;
31 return Array.isArray(families) ? families.join(", ") : families;
32 };
33 }
34 if ([
35 "boxShadow",
36 "transitionProperty",
37 "transitionDuration",
38 "transitionDelay",
39 "transitionTimingFunction",
40 "backgroundImage",
41 "backgroundSize",
42 "backgroundColor",
43 "cursor",
44 "animation"
45 ].includes(themeSection)) {
46 return (value)=>{
47 if (typeof value === "function") value = value({});
48 if (Array.isArray(value)) value = value.join(", ");
49 return value;
50 };
51 }
52 // For backwards compatibility reasons, before we switched to underscores
53 // instead of commas for arbitrary values.
54 if ([
55 "gridTemplateColumns",
56 "gridTemplateRows",
57 "objectPosition"
58 ].includes(themeSection)) {
59 return (value)=>{
60 if (typeof value === "function") value = value({});
61 if (typeof value === "string") value = _postcss.default.list.comma(value).join(" ");
62 return value;
63 };
64 }
65 return (value, opts = {})=>{
66 if (typeof value === "function") {
67 value = value(opts);
68 }
69 return value;
70 };
71}