@soroush.tech/styled-system 5.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +150 -0
- package/dist/background-B-jql3jb.mjs +16 -0
- package/dist/background-wugr6cG7.cjs +21 -0
- package/dist/background.cjs +7 -0
- package/dist/background.d.cts +2 -0
- package/dist/background.d.mts +2 -0
- package/dist/background.mjs +2 -0
- package/dist/border-Dder4Dhp.mjs +131 -0
- package/dist/border-UuT-fTpy.cjs +136 -0
- package/dist/border.cjs +7 -0
- package/dist/border.d.cts +2 -0
- package/dist/border.d.mts +2 -0
- package/dist/border.mjs +2 -0
- package/dist/color-BNs17Gw-.cjs +22 -0
- package/dist/color-CGmMe8yP.mjs +17 -0
- package/dist/color.cjs +7 -0
- package/dist/color.d.cts +2 -0
- package/dist/color.d.mts +2 -0
- package/dist/color.mjs +2 -0
- package/dist/core.cjs +144 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.mts +2 -0
- package/dist/core.mjs +138 -0
- package/dist/css-nzeM_Xnf.cjs +231 -0
- package/dist/css-rLZ9Oeye.mjs +214 -0
- package/dist/css.cjs +9 -0
- package/dist/css.d.cts +12 -0
- package/dist/css.d.mts +12 -0
- package/dist/css.mjs +2 -0
- package/dist/flexbox-CFkO6PrP.cjs +22 -0
- package/dist/flexbox-XQnlnfa4.mjs +18 -0
- package/dist/flexbox.cjs +7 -0
- package/dist/flexbox.d.cts +2 -0
- package/dist/flexbox.d.mts +2 -0
- package/dist/flexbox.mjs +2 -0
- package/dist/grid-Bpk-QjhF.mjs +41 -0
- package/dist/grid-CpvRIng4.cjs +47 -0
- package/dist/grid.cjs +7 -0
- package/dist/grid.d.cts +2 -0
- package/dist/grid.d.mts +2 -0
- package/dist/grid.mjs +2 -0
- package/dist/index-50KH4Mo7.d.cts +8 -0
- package/dist/index-8PSQ0vkP.d.cts +15 -0
- package/dist/index-9ZhIewzy.d.mts +6 -0
- package/dist/index-BBTVE4EM.d.mts +15 -0
- package/dist/index-BS9GuhQN.d.cts +6 -0
- package/dist/index-BoMacn6F.d.cts +6 -0
- package/dist/index-Bx7IxKu-.d.mts +6 -0
- package/dist/index-C13YRARN.d.mts +6 -0
- package/dist/index-C3_fScux.d.mts +8 -0
- package/dist/index-CX2jWEGJ.d.mts +6 -0
- package/dist/index-CarHCWLQ.d.cts +6 -0
- package/dist/index-Ce09s0FQ.d.cts +6 -0
- package/dist/index-CrUx2vIP.d.mts +6 -0
- package/dist/index-CsS_gcI9.d.mts +6 -0
- package/dist/index-D3t1Lyte.d.mts +6 -0
- package/dist/index-D8EyRZ5p.d.cts +62 -0
- package/dist/index-D8EyRZ5p.d.mts +62 -0
- package/dist/index-DPWkvooj.d.mts +6 -0
- package/dist/index-DVR6hZCd.d.cts +6 -0
- package/dist/index-DZaFk5pk.d.cts +6 -0
- package/dist/index-J3PebPto.d.mts +6 -0
- package/dist/index-Nc-10syf.d.cts +6 -0
- package/dist/index-j3E1mxCg.d.cts +6 -0
- package/dist/index-z86wOHTb.d.cts +6 -0
- package/dist/index.cjs +185 -0
- package/dist/index.d.cts +281 -0
- package/dist/index.d.mts +281 -0
- package/dist/index.mjs +98 -0
- package/dist/layout-B1-2dfQ9.cjs +48 -0
- package/dist/layout-TqD8vcEl.mjs +42 -0
- package/dist/layout.cjs +7 -0
- package/dist/layout.d.cts +2 -0
- package/dist/layout.d.mts +2 -0
- package/dist/layout.mjs +2 -0
- package/dist/position-jf6VlRyR.mjs +42 -0
- package/dist/position-zWvCE4hD.cjs +48 -0
- package/dist/position.cjs +7 -0
- package/dist/position.d.cts +2 -0
- package/dist/position.d.mts +2 -0
- package/dist/position.mjs +2 -0
- package/dist/presets-DjaCx0dm.mjs +16 -0
- package/dist/presets-DlUVOAIL.cjs +21 -0
- package/dist/props.cjs +23 -0
- package/dist/props.d.cts +5 -0
- package/dist/props.d.mts +5 -0
- package/dist/props.mjs +21 -0
- package/dist/shadow-Bp7lx_41.mjs +14 -0
- package/dist/shadow-BrDnaQQl.cjs +18 -0
- package/dist/shadow.cjs +7 -0
- package/dist/shadow.d.cts +2 -0
- package/dist/shadow.d.mts +2 -0
- package/dist/shadow.mjs +2 -0
- package/dist/should-forward-prop.cjs +47 -0
- package/dist/should-forward-prop.d.cts +6 -0
- package/dist/should-forward-prop.d.mts +6 -0
- package/dist/should-forward-prop.mjs +18 -0
- package/dist/space-C14uiNpw.cjs +139 -0
- package/dist/space-CNrX-zoo.mjs +122 -0
- package/dist/space.cjs +9 -0
- package/dist/space.d.cts +2 -0
- package/dist/space.d.mts +2 -0
- package/dist/space.mjs +2 -0
- package/dist/theme-get.cjs +10 -0
- package/dist/theme-get.d.cts +6 -0
- package/dist/theme-get.d.mts +6 -0
- package/dist/theme-get.mjs +5 -0
- package/dist/typography-CptBXSy0.mjs +38 -0
- package/dist/typography-DD_eWLLx.cjs +42 -0
- package/dist/typography.cjs +7 -0
- package/dist/typography.d.cts +2 -0
- package/dist/typography.d.mts +2 -0
- package/dist/typography.mjs +2 -0
- package/dist/variant-CWUfe1Cc.mjs +22 -0
- package/dist/variant-ChsBzwrI.cjs +45 -0
- package/dist/variant.cjs +10 -0
- package/dist/variant.d.cts +2 -0
- package/dist/variant.d.mts +2 -0
- package/dist/variant.mjs +2 -0
- package/package.json +255 -0
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/core/core.ts
|
|
3
|
+
const merge = (a, b) => {
|
|
4
|
+
const result = Object.assign({}, a, b);
|
|
5
|
+
for (const key in a) {
|
|
6
|
+
if (!a[key] || typeof b[key] !== "object") continue;
|
|
7
|
+
Object.assign(result, { [key]: Object.assign(a[key], b[key]) });
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
const sort = (obj) => {
|
|
12
|
+
const next = {};
|
|
13
|
+
Object.keys(obj).sort((a, b) => a.localeCompare(b, void 0, {
|
|
14
|
+
numeric: true,
|
|
15
|
+
sensitivity: "base"
|
|
16
|
+
})).forEach((key) => {
|
|
17
|
+
next[key] = obj[key];
|
|
18
|
+
});
|
|
19
|
+
return next;
|
|
20
|
+
};
|
|
21
|
+
const defaults = { breakpoints: [
|
|
22
|
+
40,
|
|
23
|
+
52,
|
|
24
|
+
64
|
|
25
|
+
].map((n) => n + "em") };
|
|
26
|
+
const createMediaQuery = (n) => `@media screen and (min-width: ${n})`;
|
|
27
|
+
const getValue = (n, scale) => get(scale, n, n);
|
|
28
|
+
const get = (obj, key, def, p, undef) => {
|
|
29
|
+
const path = typeof key === "string" ? key.split(".") : [key];
|
|
30
|
+
let value = obj;
|
|
31
|
+
for (p = 0; p < path.length; p++) value = value ? value[path[p]] : undef;
|
|
32
|
+
return value === undef ? def : value;
|
|
33
|
+
};
|
|
34
|
+
const parseResponsiveStyle = (mediaQueries, sx, scale, raw, props) => {
|
|
35
|
+
const styles = {};
|
|
36
|
+
raw.slice(0, mediaQueries.length).forEach((value, i) => {
|
|
37
|
+
const media = mediaQueries[i];
|
|
38
|
+
const style = sx(value, scale, props);
|
|
39
|
+
if (!media) Object.assign(styles, style);
|
|
40
|
+
else Object.assign(styles, { [media]: Object.assign({}, styles[media], style) });
|
|
41
|
+
});
|
|
42
|
+
return styles;
|
|
43
|
+
};
|
|
44
|
+
const parseResponsiveObject = (breakpoints, sx, scale, raw, props) => {
|
|
45
|
+
const styles = {};
|
|
46
|
+
for (const key in raw) {
|
|
47
|
+
const breakpoint = breakpoints[key];
|
|
48
|
+
const value = raw[key];
|
|
49
|
+
const style = sx(value, scale, props);
|
|
50
|
+
if (!breakpoint) Object.assign(styles, style);
|
|
51
|
+
else {
|
|
52
|
+
const media = createMediaQuery(breakpoint);
|
|
53
|
+
Object.assign(styles, { [media]: Object.assign({}, styles[media], style) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return styles;
|
|
57
|
+
};
|
|
58
|
+
const createParser = (config) => {
|
|
59
|
+
const cache = {};
|
|
60
|
+
const parse = ((props) => {
|
|
61
|
+
let styles = {};
|
|
62
|
+
let shouldSort = false;
|
|
63
|
+
const isCacheDisabled = props.theme && props.theme.disableStyledSystemCache;
|
|
64
|
+
for (const key in props) {
|
|
65
|
+
if (!config[key]) continue;
|
|
66
|
+
const sx = config[key];
|
|
67
|
+
const raw = props[key];
|
|
68
|
+
const scale = get(props.theme, sx.scale, sx.defaults);
|
|
69
|
+
if (typeof raw === "object") {
|
|
70
|
+
cache.breakpoints = !isCacheDisabled && cache.breakpoints || get(props.theme, "breakpoints", defaults.breakpoints);
|
|
71
|
+
if (Array.isArray(raw)) {
|
|
72
|
+
cache.media = !isCacheDisabled && cache.media || [null, ...cache.breakpoints.map(createMediaQuery)];
|
|
73
|
+
styles = merge(styles, parseResponsiveStyle(cache.media, sx, scale, raw, props));
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (raw !== null) {
|
|
77
|
+
styles = merge(styles, parseResponsiveObject(cache.breakpoints, sx, scale, raw, props));
|
|
78
|
+
shouldSort = true;
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
Object.assign(styles, sx(raw, scale, props));
|
|
83
|
+
}
|
|
84
|
+
if (shouldSort) styles = sort(styles);
|
|
85
|
+
return styles;
|
|
86
|
+
});
|
|
87
|
+
parse.config = config;
|
|
88
|
+
parse.propNames = Object.keys(config);
|
|
89
|
+
parse.cache = cache;
|
|
90
|
+
const keys = Object.keys(config).filter((k) => k !== "config");
|
|
91
|
+
if (keys.length > 1) keys.forEach((key) => {
|
|
92
|
+
Object.assign(parse, { [key]: createParser({ [key]: config[key] }) });
|
|
93
|
+
});
|
|
94
|
+
return parse;
|
|
95
|
+
};
|
|
96
|
+
const createStyleFunction = ({ properties, property, scale, transform = getValue, defaultScale }) => {
|
|
97
|
+
const props = properties || [property];
|
|
98
|
+
const sx = (value, scaleArg, styleProps) => {
|
|
99
|
+
const result = {};
|
|
100
|
+
const n = transform(value, scaleArg, styleProps);
|
|
101
|
+
if (n === null) return;
|
|
102
|
+
props.forEach((prop) => {
|
|
103
|
+
result[prop] = n;
|
|
104
|
+
});
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
sx.scale = scale;
|
|
108
|
+
sx.defaults = defaultScale;
|
|
109
|
+
return sx;
|
|
110
|
+
};
|
|
111
|
+
const system = (args = {}) => {
|
|
112
|
+
const config = {};
|
|
113
|
+
Object.keys(args).forEach((key) => {
|
|
114
|
+
const conf = args[key];
|
|
115
|
+
if (conf === true) {
|
|
116
|
+
config[key] = createStyleFunction({
|
|
117
|
+
property: key,
|
|
118
|
+
scale: key
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (typeof conf === "function") {
|
|
123
|
+
config[key] = conf;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
config[key] = createStyleFunction(conf);
|
|
127
|
+
});
|
|
128
|
+
return createParser(config);
|
|
129
|
+
};
|
|
130
|
+
const compose = (...parsers) => {
|
|
131
|
+
const config = {};
|
|
132
|
+
parsers.forEach((parser) => {
|
|
133
|
+
if (!parser || !parser.config) return;
|
|
134
|
+
Object.assign(config, parser.config);
|
|
135
|
+
});
|
|
136
|
+
return createParser(config);
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
exports.compose = compose;
|
|
140
|
+
exports.createParser = createParser;
|
|
141
|
+
exports.createStyleFunction = createStyleFunction;
|
|
142
|
+
exports.get = get;
|
|
143
|
+
exports.merge = merge;
|
|
144
|
+
exports.system = system;
|
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as Props, c as SystemConfig, d as compose, f as createParser, g as system, h as merge, i as ParserConfig, l as Theme, m as get, n as ConfigStyle, o as StyleFn, p as createStyleFunction, r as Parser, s as StyleObject, t as CSSObject, u as Transform } from "./index-D8EyRZ5p.cjs";
|
|
2
|
+
export { CSSObject, ConfigStyle, Parser, ParserConfig, Props, StyleFn, StyleObject, SystemConfig, Theme, Transform, compose, createParser, createStyleFunction, get, merge, system };
|
package/dist/core.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as Props, c as SystemConfig, d as compose, f as createParser, g as system, h as merge, i as ParserConfig, l as Theme, m as get, n as ConfigStyle, o as StyleFn, p as createStyleFunction, r as Parser, s as StyleObject, t as CSSObject, u as Transform } from "./index-D8EyRZ5p.mjs";
|
|
2
|
+
export { CSSObject, ConfigStyle, Parser, ParserConfig, Props, StyleFn, StyleObject, SystemConfig, Theme, Transform, compose, createParser, createStyleFunction, get, merge, system };
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//#region src/core/core.ts
|
|
2
|
+
const merge = (a, b) => {
|
|
3
|
+
const result = Object.assign({}, a, b);
|
|
4
|
+
for (const key in a) {
|
|
5
|
+
if (!a[key] || typeof b[key] !== "object") continue;
|
|
6
|
+
Object.assign(result, { [key]: Object.assign(a[key], b[key]) });
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
const sort = (obj) => {
|
|
11
|
+
const next = {};
|
|
12
|
+
Object.keys(obj).sort((a, b) => a.localeCompare(b, void 0, {
|
|
13
|
+
numeric: true,
|
|
14
|
+
sensitivity: "base"
|
|
15
|
+
})).forEach((key) => {
|
|
16
|
+
next[key] = obj[key];
|
|
17
|
+
});
|
|
18
|
+
return next;
|
|
19
|
+
};
|
|
20
|
+
const defaults = { breakpoints: [
|
|
21
|
+
40,
|
|
22
|
+
52,
|
|
23
|
+
64
|
|
24
|
+
].map((n) => n + "em") };
|
|
25
|
+
const createMediaQuery = (n) => `@media screen and (min-width: ${n})`;
|
|
26
|
+
const getValue = (n, scale) => get(scale, n, n);
|
|
27
|
+
const get = (obj, key, def, p, undef) => {
|
|
28
|
+
const path = typeof key === "string" ? key.split(".") : [key];
|
|
29
|
+
let value = obj;
|
|
30
|
+
for (p = 0; p < path.length; p++) value = value ? value[path[p]] : undef;
|
|
31
|
+
return value === undef ? def : value;
|
|
32
|
+
};
|
|
33
|
+
const parseResponsiveStyle = (mediaQueries, sx, scale, raw, props) => {
|
|
34
|
+
const styles = {};
|
|
35
|
+
raw.slice(0, mediaQueries.length).forEach((value, i) => {
|
|
36
|
+
const media = mediaQueries[i];
|
|
37
|
+
const style = sx(value, scale, props);
|
|
38
|
+
if (!media) Object.assign(styles, style);
|
|
39
|
+
else Object.assign(styles, { [media]: Object.assign({}, styles[media], style) });
|
|
40
|
+
});
|
|
41
|
+
return styles;
|
|
42
|
+
};
|
|
43
|
+
const parseResponsiveObject = (breakpoints, sx, scale, raw, props) => {
|
|
44
|
+
const styles = {};
|
|
45
|
+
for (const key in raw) {
|
|
46
|
+
const breakpoint = breakpoints[key];
|
|
47
|
+
const value = raw[key];
|
|
48
|
+
const style = sx(value, scale, props);
|
|
49
|
+
if (!breakpoint) Object.assign(styles, style);
|
|
50
|
+
else {
|
|
51
|
+
const media = createMediaQuery(breakpoint);
|
|
52
|
+
Object.assign(styles, { [media]: Object.assign({}, styles[media], style) });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return styles;
|
|
56
|
+
};
|
|
57
|
+
const createParser = (config) => {
|
|
58
|
+
const cache = {};
|
|
59
|
+
const parse = ((props) => {
|
|
60
|
+
let styles = {};
|
|
61
|
+
let shouldSort = false;
|
|
62
|
+
const isCacheDisabled = props.theme && props.theme.disableStyledSystemCache;
|
|
63
|
+
for (const key in props) {
|
|
64
|
+
if (!config[key]) continue;
|
|
65
|
+
const sx = config[key];
|
|
66
|
+
const raw = props[key];
|
|
67
|
+
const scale = get(props.theme, sx.scale, sx.defaults);
|
|
68
|
+
if (typeof raw === "object") {
|
|
69
|
+
cache.breakpoints = !isCacheDisabled && cache.breakpoints || get(props.theme, "breakpoints", defaults.breakpoints);
|
|
70
|
+
if (Array.isArray(raw)) {
|
|
71
|
+
cache.media = !isCacheDisabled && cache.media || [null, ...cache.breakpoints.map(createMediaQuery)];
|
|
72
|
+
styles = merge(styles, parseResponsiveStyle(cache.media, sx, scale, raw, props));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (raw !== null) {
|
|
76
|
+
styles = merge(styles, parseResponsiveObject(cache.breakpoints, sx, scale, raw, props));
|
|
77
|
+
shouldSort = true;
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
Object.assign(styles, sx(raw, scale, props));
|
|
82
|
+
}
|
|
83
|
+
if (shouldSort) styles = sort(styles);
|
|
84
|
+
return styles;
|
|
85
|
+
});
|
|
86
|
+
parse.config = config;
|
|
87
|
+
parse.propNames = Object.keys(config);
|
|
88
|
+
parse.cache = cache;
|
|
89
|
+
const keys = Object.keys(config).filter((k) => k !== "config");
|
|
90
|
+
if (keys.length > 1) keys.forEach((key) => {
|
|
91
|
+
Object.assign(parse, { [key]: createParser({ [key]: config[key] }) });
|
|
92
|
+
});
|
|
93
|
+
return parse;
|
|
94
|
+
};
|
|
95
|
+
const createStyleFunction = ({ properties, property, scale, transform = getValue, defaultScale }) => {
|
|
96
|
+
const props = properties || [property];
|
|
97
|
+
const sx = (value, scaleArg, styleProps) => {
|
|
98
|
+
const result = {};
|
|
99
|
+
const n = transform(value, scaleArg, styleProps);
|
|
100
|
+
if (n === null) return;
|
|
101
|
+
props.forEach((prop) => {
|
|
102
|
+
result[prop] = n;
|
|
103
|
+
});
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
106
|
+
sx.scale = scale;
|
|
107
|
+
sx.defaults = defaultScale;
|
|
108
|
+
return sx;
|
|
109
|
+
};
|
|
110
|
+
const system = (args = {}) => {
|
|
111
|
+
const config = {};
|
|
112
|
+
Object.keys(args).forEach((key) => {
|
|
113
|
+
const conf = args[key];
|
|
114
|
+
if (conf === true) {
|
|
115
|
+
config[key] = createStyleFunction({
|
|
116
|
+
property: key,
|
|
117
|
+
scale: key
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (typeof conf === "function") {
|
|
122
|
+
config[key] = conf;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
config[key] = createStyleFunction(conf);
|
|
126
|
+
});
|
|
127
|
+
return createParser(config);
|
|
128
|
+
};
|
|
129
|
+
const compose = (...parsers) => {
|
|
130
|
+
const config = {};
|
|
131
|
+
parsers.forEach((parser) => {
|
|
132
|
+
if (!parser || !parser.config) return;
|
|
133
|
+
Object.assign(config, parser.config);
|
|
134
|
+
});
|
|
135
|
+
return createParser(config);
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
export { compose, createParser, createStyleFunction, get, merge, system };
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
//#region src/css/css.ts
|
|
2
|
+
const get = (obj, key, def, p, undef) => {
|
|
3
|
+
const path = typeof key === "string" ? key.split(".") : [key];
|
|
4
|
+
let value = obj;
|
|
5
|
+
for (p = 0; p < path.length; p++) value = value ? value[path[p]] : undef;
|
|
6
|
+
return value === undef ? def : value;
|
|
7
|
+
};
|
|
8
|
+
const defaultBreakpoints = [
|
|
9
|
+
40,
|
|
10
|
+
52,
|
|
11
|
+
64
|
|
12
|
+
].map((n) => n + "em");
|
|
13
|
+
const defaultTheme = {
|
|
14
|
+
space: [
|
|
15
|
+
0,
|
|
16
|
+
4,
|
|
17
|
+
8,
|
|
18
|
+
16,
|
|
19
|
+
32,
|
|
20
|
+
64,
|
|
21
|
+
128,
|
|
22
|
+
256,
|
|
23
|
+
512
|
|
24
|
+
],
|
|
25
|
+
fontSizes: [
|
|
26
|
+
12,
|
|
27
|
+
14,
|
|
28
|
+
16,
|
|
29
|
+
20,
|
|
30
|
+
24,
|
|
31
|
+
32,
|
|
32
|
+
48,
|
|
33
|
+
64,
|
|
34
|
+
72
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
const aliases = {
|
|
38
|
+
bg: "backgroundColor",
|
|
39
|
+
m: "margin",
|
|
40
|
+
mt: "marginTop",
|
|
41
|
+
mr: "marginRight",
|
|
42
|
+
mb: "marginBottom",
|
|
43
|
+
ml: "marginLeft",
|
|
44
|
+
mx: "marginX",
|
|
45
|
+
my: "marginY",
|
|
46
|
+
p: "padding",
|
|
47
|
+
pt: "paddingTop",
|
|
48
|
+
pr: "paddingRight",
|
|
49
|
+
pb: "paddingBottom",
|
|
50
|
+
pl: "paddingLeft",
|
|
51
|
+
px: "paddingX",
|
|
52
|
+
py: "paddingY"
|
|
53
|
+
};
|
|
54
|
+
const multiples = {
|
|
55
|
+
marginX: ["marginLeft", "marginRight"],
|
|
56
|
+
marginY: ["marginTop", "marginBottom"],
|
|
57
|
+
paddingX: ["paddingLeft", "paddingRight"],
|
|
58
|
+
paddingY: ["paddingTop", "paddingBottom"],
|
|
59
|
+
size: ["width", "height"]
|
|
60
|
+
};
|
|
61
|
+
const scales = {
|
|
62
|
+
color: "colors",
|
|
63
|
+
backgroundColor: "colors",
|
|
64
|
+
borderColor: "colors",
|
|
65
|
+
margin: "space",
|
|
66
|
+
marginTop: "space",
|
|
67
|
+
marginRight: "space",
|
|
68
|
+
marginBottom: "space",
|
|
69
|
+
marginLeft: "space",
|
|
70
|
+
marginX: "space",
|
|
71
|
+
marginY: "space",
|
|
72
|
+
padding: "space",
|
|
73
|
+
paddingTop: "space",
|
|
74
|
+
paddingRight: "space",
|
|
75
|
+
paddingBottom: "space",
|
|
76
|
+
paddingLeft: "space",
|
|
77
|
+
paddingX: "space",
|
|
78
|
+
paddingY: "space",
|
|
79
|
+
top: "space",
|
|
80
|
+
right: "space",
|
|
81
|
+
bottom: "space",
|
|
82
|
+
left: "space",
|
|
83
|
+
gridGap: "space",
|
|
84
|
+
gridColumnGap: "space",
|
|
85
|
+
gridRowGap: "space",
|
|
86
|
+
gap: "space",
|
|
87
|
+
columnGap: "space",
|
|
88
|
+
rowGap: "space",
|
|
89
|
+
fontFamily: "fonts",
|
|
90
|
+
fontSize: "fontSizes",
|
|
91
|
+
fontWeight: "fontWeights",
|
|
92
|
+
lineHeight: "lineHeights",
|
|
93
|
+
letterSpacing: "letterSpacings",
|
|
94
|
+
border: "borders",
|
|
95
|
+
borderTop: "borders",
|
|
96
|
+
borderRight: "borders",
|
|
97
|
+
borderBottom: "borders",
|
|
98
|
+
borderLeft: "borders",
|
|
99
|
+
borderWidth: "borderWidths",
|
|
100
|
+
borderStyle: "borderStyles",
|
|
101
|
+
borderRadius: "radii",
|
|
102
|
+
borderTopRightRadius: "radii",
|
|
103
|
+
borderTopLeftRadius: "radii",
|
|
104
|
+
borderBottomRightRadius: "radii",
|
|
105
|
+
borderBottomLeftRadius: "radii",
|
|
106
|
+
borderTopWidth: "borderWidths",
|
|
107
|
+
borderTopColor: "colors",
|
|
108
|
+
borderTopStyle: "borderStyles",
|
|
109
|
+
borderBottomWidth: "borderWidths",
|
|
110
|
+
borderBottomColor: "colors",
|
|
111
|
+
borderBottomStyle: "borderStyles",
|
|
112
|
+
borderLeftWidth: "borderWidths",
|
|
113
|
+
borderLeftColor: "colors",
|
|
114
|
+
borderLeftStyle: "borderStyles",
|
|
115
|
+
borderRightWidth: "borderWidths",
|
|
116
|
+
borderRightColor: "colors",
|
|
117
|
+
borderRightStyle: "borderStyles",
|
|
118
|
+
outlineColor: "colors",
|
|
119
|
+
boxShadow: "shadows",
|
|
120
|
+
textShadow: "shadows",
|
|
121
|
+
zIndex: "zIndices",
|
|
122
|
+
width: "sizes",
|
|
123
|
+
minWidth: "sizes",
|
|
124
|
+
maxWidth: "sizes",
|
|
125
|
+
height: "sizes",
|
|
126
|
+
minHeight: "sizes",
|
|
127
|
+
maxHeight: "sizes",
|
|
128
|
+
flexBasis: "sizes",
|
|
129
|
+
size: "sizes",
|
|
130
|
+
fill: "colors",
|
|
131
|
+
stroke: "colors"
|
|
132
|
+
};
|
|
133
|
+
const positiveOrNegative = (scale, value) => {
|
|
134
|
+
if (typeof value !== "number" || value >= 0) return get(scale, value, value);
|
|
135
|
+
const absolute = Math.abs(value);
|
|
136
|
+
const n = get(scale, absolute, absolute);
|
|
137
|
+
if (typeof n === "string") return "-" + n;
|
|
138
|
+
return n * -1;
|
|
139
|
+
};
|
|
140
|
+
const transforms = [
|
|
141
|
+
"margin",
|
|
142
|
+
"marginTop",
|
|
143
|
+
"marginRight",
|
|
144
|
+
"marginBottom",
|
|
145
|
+
"marginLeft",
|
|
146
|
+
"marginX",
|
|
147
|
+
"marginY",
|
|
148
|
+
"top",
|
|
149
|
+
"bottom",
|
|
150
|
+
"left",
|
|
151
|
+
"right"
|
|
152
|
+
].reduce((acc, curr) => ({
|
|
153
|
+
...acc,
|
|
154
|
+
[curr]: positiveOrNegative
|
|
155
|
+
}), {});
|
|
156
|
+
const responsive = (styles) => (theme) => {
|
|
157
|
+
const next = {};
|
|
158
|
+
const mediaQueries = [null, ...get(theme, "breakpoints", defaultBreakpoints).map((n) => `@media screen and (min-width: ${n})`)];
|
|
159
|
+
for (const key in styles) {
|
|
160
|
+
const value = typeof styles[key] === "function" ? styles[key](theme) : styles[key];
|
|
161
|
+
if (value == null) continue;
|
|
162
|
+
if (!Array.isArray(value)) {
|
|
163
|
+
next[key] = value;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const slice = value.slice(0, mediaQueries.length);
|
|
167
|
+
for (let i = 0; i < slice.length; i++) {
|
|
168
|
+
const media = mediaQueries[i];
|
|
169
|
+
if (!media) {
|
|
170
|
+
next[key] = slice[i];
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const block = next[media] || {};
|
|
174
|
+
next[media] = block;
|
|
175
|
+
if (slice[i] == null) continue;
|
|
176
|
+
block[key] = slice[i];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return next;
|
|
180
|
+
};
|
|
181
|
+
const css = (args) => (props = {}) => {
|
|
182
|
+
const theme = {
|
|
183
|
+
...defaultTheme,
|
|
184
|
+
...props.theme || props
|
|
185
|
+
};
|
|
186
|
+
let result = {};
|
|
187
|
+
const styles = responsive(typeof args === "function" ? args(theme) : args)(theme);
|
|
188
|
+
for (const key in styles) {
|
|
189
|
+
const x = styles[key];
|
|
190
|
+
const val = typeof x === "function" ? x(theme) : x;
|
|
191
|
+
if (key === "variant") {
|
|
192
|
+
const variant = css(get(theme, val))(theme);
|
|
193
|
+
result = {
|
|
194
|
+
...result,
|
|
195
|
+
...variant
|
|
196
|
+
};
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (val && typeof val === "object") {
|
|
200
|
+
result[key] = css(val)(theme);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const prop = get(aliases, key, key);
|
|
204
|
+
const scale = get(theme, get(scales, prop), get(theme, prop, {}));
|
|
205
|
+
const value = get(transforms, prop, get)(scale, val, val);
|
|
206
|
+
if (multiples[prop]) {
|
|
207
|
+
const dirs = multiples[prop];
|
|
208
|
+
for (let i = 0; i < dirs.length; i++) result[dirs[i]] = value;
|
|
209
|
+
} else result[prop] = value;
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
};
|
|
213
|
+
//#endregion
|
|
214
|
+
Object.defineProperty(exports, "css", {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
get: function() {
|
|
217
|
+
return css;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(exports, "get", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function() {
|
|
223
|
+
return get;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(exports, "responsive", {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
get: function() {
|
|
229
|
+
return responsive;
|
|
230
|
+
}
|
|
231
|
+
});
|