@slimr/css 2.1.74 → 2.1.76
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/cjs/addCss.js +1 -1
- package/cjs/addCss.js.map +1 -1
- package/cjs/addCss.ts +11 -11
- package/cjs/createClass.d.ts +1 -1
- package/cjs/createClass.js +30 -30
- package/cjs/createClass.js.map +1 -1
- package/cjs/createClass.ts +106 -106
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/index.ts +4 -4
- package/cjs/shorthandProps.d.ts +1 -1
- package/cjs/shorthandProps.js +31 -31
- package/cjs/shorthandProps.js.map +1 -1
- package/cjs/shorthandProps.ts +100 -100
- package/esm/addCss.js +2 -2
- package/esm/addCss.js.map +1 -1
- package/esm/addCss.ts +11 -11
- package/esm/createClass.d.ts +1 -1
- package/esm/createClass.js +33 -33
- package/esm/createClass.js.map +1 -1
- package/esm/createClass.ts +106 -106
- package/esm/index.d.ts +4 -4
- package/esm/index.js +4 -4
- package/esm/index.js.map +1 -1
- package/esm/index.ts +4 -4
- package/esm/shorthandProps.d.ts +1 -1
- package/esm/shorthandProps.js +31 -31
- package/esm/shorthandProps.js.map +1 -1
- package/esm/shorthandProps.ts +100 -100
- package/package.json +2 -2
- package/src/addCss.ts +11 -11
- package/src/createClass.ts +106 -106
- package/src/index.ts +4 -4
- package/src/shorthandProps.ts +100 -100
- package/tsconfig.json +5 -5
package/esm/createClass.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {T2SProps, t2s} from
|
|
1
|
+
import { type T2SProps, t2s } from "@slimr/util"
|
|
2
2
|
|
|
3
|
-
import {addCss} from
|
|
4
|
-
import {expandShorthands} from
|
|
3
|
+
import { addCss } from "./addCss.js"
|
|
4
|
+
import { expandShorthands } from "./shorthandProps.js"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Joins class names and omits falsey props
|
|
@@ -18,7 +18,7 @@ import {expandShorthands} from './shorthandProps.js'
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export function classJoin(...classes: (string | 0 | null | undefined)[]) {
|
|
21
|
-
|
|
21
|
+
return classes.filter((c) => c && typeof c === "string").join(" ")
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -43,50 +43,50 @@ export function classJoin(...classes: (string | 0 | null | undefined)[]) {
|
|
|
43
43
|
* ...and the queue will be executed next javascript tick
|
|
44
44
|
*/
|
|
45
45
|
export function createClass(...p: T2SProps) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
let css = t2s(...p)
|
|
47
|
+
if (!css) return ""
|
|
48
|
+
let className = createClass.history.get(css)
|
|
49
|
+
if (!className) {
|
|
50
|
+
className = `s${createClass.count++}`
|
|
51
|
+
createClass.history.set(css, className)
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
css = deleteComments(css)
|
|
54
|
+
css = expandShorthands(css)
|
|
55
|
+
css = expandArrayValues(css)
|
|
56
|
+
const qs = findQueries(css)
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
for (const q of qs.reverse()) {
|
|
59
|
+
css = css.slice(0, q.start) + css.slice(q.end)
|
|
60
|
+
}
|
|
61
|
+
qs.reverse()
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
css = `.${className}{\n${css}\n}\n`
|
|
64
|
+
css += qs
|
|
65
|
+
.map((q) => {
|
|
66
|
+
if (q.query.startsWith("&")) {
|
|
67
|
+
return `.${className}${q.query.slice(1)}{\n${q.innerBody}\n}`
|
|
68
|
+
}
|
|
69
|
+
if (q.query.startsWith("@keyframes")) {
|
|
70
|
+
return q.outerBody
|
|
71
|
+
}
|
|
72
|
+
return `${q.query}{\n.${className}{${q.innerBody}\n}\n}`
|
|
73
|
+
})
|
|
74
|
+
.join("\n")
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
css = `${trimByLine(css)}\n\n`
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
addCss(css)
|
|
79
|
+
}
|
|
80
|
+
return className
|
|
81
81
|
}
|
|
82
82
|
/** Breakpoints like chakra */
|
|
83
|
-
createClass.breakPoints = [
|
|
83
|
+
createClass.breakPoints = ["30em", "48em", "62em", "80em", "96em"]
|
|
84
84
|
createClass.count = 0
|
|
85
85
|
createClass.history = new Map<string, string>()
|
|
86
86
|
|
|
87
87
|
/** delete css comments **/
|
|
88
88
|
function deleteComments(css: string) {
|
|
89
|
-
|
|
89
|
+
return css.replace(/{\/\*[\s\S]*?(?=\*\/})\*\/}/gm, "")
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -95,82 +95,82 @@ function deleteComments(css: string) {
|
|
|
95
95
|
* Inspired by https://chakra-ui.com/docs/styled-system/responsive-styles
|
|
96
96
|
*/
|
|
97
97
|
function expandArrayValues(css: string) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
98
|
+
if (!css.includes("[")) return css
|
|
99
|
+
return css
|
|
100
|
+
.split("\n")
|
|
101
|
+
.map((l) => {
|
|
102
|
+
// eslint-disable-next-line no-useless-escape
|
|
103
|
+
const [, prop, valArrayStr] = [...l.matchAll(/([A-Za-z-]*):[ ]*\[([^\]]+)\]/g)]?.[0] ?? []
|
|
104
|
+
if (valArrayStr) {
|
|
105
|
+
return (
|
|
106
|
+
valArrayStr
|
|
107
|
+
// Replace commas inside css functions with a magic char (§) to prevent
|
|
108
|
+
// erroneous splitting
|
|
109
|
+
.replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
|
|
110
|
+
.replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
|
|
111
|
+
.replace(/\([^),]*,/g, (m) => m.replace(/,/g, "§"))
|
|
112
|
+
.split(",")
|
|
113
|
+
.map((val, i) => {
|
|
114
|
+
val = val.trim()
|
|
115
|
+
if (!val || val === "null" || val === "undefined") return ""
|
|
116
|
+
val = val.replace(/§/g, ",")
|
|
117
|
+
if (i === 0) {
|
|
118
|
+
return `${prop}: ${val};`
|
|
119
|
+
}
|
|
120
|
+
return `@media (min-width: ${createClass.breakPoints[i - 1]}) { ${prop}: ${val}; }`
|
|
121
|
+
})
|
|
122
|
+
.join("\n")
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
return l
|
|
126
|
+
})
|
|
127
|
+
.join("\n")
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/** Find @keyframes, @media, @container queries in css **/
|
|
131
131
|
function findQueries(css: string) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
132
|
+
const queries: {
|
|
133
|
+
start: number
|
|
134
|
+
end: number
|
|
135
|
+
query: string
|
|
136
|
+
outerBody: string
|
|
137
|
+
innerBody: string
|
|
138
|
+
}[] = []
|
|
139
|
+
for (const m of css.matchAll(/[@&]/gm)) {
|
|
140
|
+
let query = ""
|
|
141
|
+
let bodyStart = 0
|
|
142
|
+
let openCount = 0
|
|
143
|
+
for (let i = m.index!; i < css.length; i++) {
|
|
144
|
+
if (css[i] === "{") {
|
|
145
|
+
if (openCount === 0) {
|
|
146
|
+
query = css.slice(m.index, i).trim()
|
|
147
|
+
bodyStart = i + 1
|
|
148
|
+
}
|
|
149
|
+
openCount++
|
|
150
|
+
} else if (css[i] === "}") {
|
|
151
|
+
openCount--
|
|
152
|
+
if (openCount === 0) {
|
|
153
|
+
queries.push({
|
|
154
|
+
start: m.index!,
|
|
155
|
+
end: i + 1,
|
|
156
|
+
query,
|
|
157
|
+
outerBody: css.slice(m.index, i + 1),
|
|
158
|
+
innerBody: css.slice(bodyStart, i),
|
|
159
|
+
})
|
|
160
|
+
break
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (openCount !== 0) console.error(`${query} not closed: "${css}"`)
|
|
165
|
+
}
|
|
166
|
+
return queries
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/** Trims whitespace for every line */
|
|
170
170
|
function trimByLine(css: string) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
return css
|
|
172
|
+
.split("\n")
|
|
173
|
+
.map((l) => l.trim())
|
|
174
|
+
.filter((l) => l)
|
|
175
|
+
.join("\n")
|
|
176
176
|
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./addCss.js";
|
|
2
|
+
export * from "./createClass.js";
|
|
3
|
+
export { createClass as css } from "./createClass.js";
|
|
4
|
+
export * from "./shorthandProps.js";
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./addCss.js";
|
|
2
|
+
export * from "./createClass.js";
|
|
3
|
+
export { createClass as css } from "./createClass.js";
|
|
4
|
+
export * from "./shorthandProps.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACrD,cAAc,qBAAqB,CAAA"}
|
package/esm/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./addCss.js"
|
|
2
|
+
export * from "./createClass.js"
|
|
3
|
+
export { createClass as css } from "./createClass.js"
|
|
4
|
+
export * from "./shorthandProps.js"
|
package/esm/shorthandProps.d.ts
CHANGED
|
@@ -72,4 +72,4 @@ export declare function expandShorthands(css: string): string;
|
|
|
72
72
|
/**
|
|
73
73
|
* Map shorthand props to their full css prop
|
|
74
74
|
*/
|
|
75
|
-
export declare const shorthandPropsMap: Record<keyof Omit<ShorthandProps,
|
|
75
|
+
export declare const shorthandPropsMap: Record<keyof Omit<ShorthandProps, "mx" | "my" | "px" | "py">, string>;
|
package/esm/shorthandProps.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Expand short-hand css props to full
|
|
3
3
|
*/
|
|
4
4
|
export function expandShorthands(css) {
|
|
5
|
-
css =
|
|
5
|
+
css = `\n${css}`; // inject a newline to make the regex easier
|
|
6
6
|
// Handle 'mx', 'my', 'px', 'py'
|
|
7
7
|
css = css
|
|
8
|
-
.replace(/([mp])x:([^;]*)/g,
|
|
9
|
-
.replace(/([mp])y:([^;]*);/g,
|
|
8
|
+
.replace(/([mp])x:([^;]*)/g, "$1l:$2;\n$1r:$2")
|
|
9
|
+
.replace(/([mp])y:([^;]*);/g, "$1t:$2;\n$1b:$2");
|
|
10
10
|
Object.entries(shorthandPropsMap).forEach(([k, v]) => {
|
|
11
|
-
css = css.replace(new RegExp(`([ \n\t;])${k}:`,
|
|
11
|
+
css = css.replace(new RegExp(`([ \n\t;])${k}:`, "g"), `$1${v}:`);
|
|
12
12
|
});
|
|
13
13
|
return css.trim();
|
|
14
14
|
}
|
|
@@ -16,32 +16,32 @@ export function expandShorthands(css) {
|
|
|
16
16
|
* Map shorthand props to their full css prop
|
|
17
17
|
*/
|
|
18
18
|
export const shorthandPropsMap = {
|
|
19
|
-
ai:
|
|
20
|
-
b:
|
|
21
|
-
br:
|
|
22
|
-
bg:
|
|
23
|
-
c:
|
|
24
|
-
d:
|
|
25
|
-
f:
|
|
26
|
-
fd:
|
|
27
|
-
i:
|
|
28
|
-
h:
|
|
29
|
-
jc:
|
|
30
|
-
m:
|
|
31
|
-
ml:
|
|
32
|
-
mr:
|
|
33
|
-
mt:
|
|
34
|
-
mb:
|
|
35
|
-
maxW:
|
|
36
|
-
minW:
|
|
37
|
-
p:
|
|
38
|
-
pl:
|
|
39
|
-
pr:
|
|
40
|
-
pt:
|
|
41
|
-
pb:
|
|
42
|
-
pos:
|
|
43
|
-
ta:
|
|
44
|
-
w:
|
|
45
|
-
z:
|
|
19
|
+
ai: "align-items",
|
|
20
|
+
b: "border",
|
|
21
|
+
br: "border-radius",
|
|
22
|
+
bg: "background",
|
|
23
|
+
c: "color",
|
|
24
|
+
d: "display",
|
|
25
|
+
f: "flex",
|
|
26
|
+
fd: "flex-direction",
|
|
27
|
+
i: "inset",
|
|
28
|
+
h: "height",
|
|
29
|
+
jc: "justify-content",
|
|
30
|
+
m: "margin",
|
|
31
|
+
ml: "margin-left",
|
|
32
|
+
mr: "margin-right",
|
|
33
|
+
mt: "margin-top",
|
|
34
|
+
mb: "margin-bottom",
|
|
35
|
+
maxW: "max-width",
|
|
36
|
+
minW: "min-width",
|
|
37
|
+
p: "padding",
|
|
38
|
+
pl: "padding-left",
|
|
39
|
+
pr: "padding-right",
|
|
40
|
+
pt: "padding-top",
|
|
41
|
+
pb: "padding-bottom",
|
|
42
|
+
pos: "position",
|
|
43
|
+
ta: "text-align",
|
|
44
|
+
w: "width",
|
|
45
|
+
z: "z-index",
|
|
46
46
|
};
|
|
47
47
|
//# sourceMappingURL=shorthandProps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shorthandProps.js","sourceRoot":"","sources":["../src/shorthandProps.ts"],"names":[],"mappings":"AAoEA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;
|
|
1
|
+
{"version":3,"file":"shorthandProps.js","sourceRoot":"","sources":["../src/shorthandProps.ts"],"names":[],"mappings":"AAoEA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,GAAG,GAAG,KAAK,GAAG,EAAE,CAAA,CAAC,4CAA4C;IAC7D,gCAAgC;IAChC,GAAG,GAAG,GAAG;SACP,OAAO,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;SAC9C,OAAO,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAAA;IACjD,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QACpD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjE,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAG1B;IACH,EAAE,EAAE,aAAa;IACjB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,gBAAgB;IACpB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,iBAAiB;IACrB,CAAC,EAAE,QAAQ;IACX,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;IACjB,CAAC,EAAE,SAAS;IACZ,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,gBAAgB;IACpB,GAAG,EAAE,UAAU;IACf,EAAE,EAAE,YAAY;IAChB,CAAC,EAAE,OAAO;IACV,CAAC,EAAE,SAAS;CACZ,CAAA"}
|
package/esm/shorthandProps.ts
CHANGED
|
@@ -2,117 +2,117 @@
|
|
|
2
2
|
* All the shorthand props that can be used in the css prop
|
|
3
3
|
*/
|
|
4
4
|
export interface ShorthandProps {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
5
|
+
/** shorthand for css:align-items */
|
|
6
|
+
ai?: string
|
|
7
|
+
/** shorthand for css:border */
|
|
8
|
+
b?: string | number
|
|
9
|
+
/** shorthand for css:border-radius */
|
|
10
|
+
br?: string | number
|
|
11
|
+
/** shorthand for css:background */
|
|
12
|
+
bg?: string
|
|
13
|
+
/** shorthand for css:color */
|
|
14
|
+
c?: string
|
|
15
|
+
/** shorthand for css:display */
|
|
16
|
+
d?: string
|
|
17
|
+
/** shorthand for css:flex */
|
|
18
|
+
f?: string
|
|
19
|
+
/** shorthand for css:flex-direction */
|
|
20
|
+
fd?: string
|
|
21
|
+
/** shorthand for css:height */
|
|
22
|
+
h?: number | string
|
|
23
|
+
/** shorthand for css:inset */
|
|
24
|
+
i?: number | string
|
|
25
|
+
/** shorthand for css:justify-content */
|
|
26
|
+
jc?: string
|
|
27
|
+
/** shorthand for css:margin */
|
|
28
|
+
m?: number | string
|
|
29
|
+
/** shorthand for css:margin-left */
|
|
30
|
+
ml?: number | string
|
|
31
|
+
/** shorthand for css:margin-right */
|
|
32
|
+
mr?: number | string
|
|
33
|
+
/** shorthand for css:margin-top */
|
|
34
|
+
mt?: number | string
|
|
35
|
+
/** shorthand for css:margin-bottom */
|
|
36
|
+
mb?: number | string
|
|
37
|
+
/** shorthand for css:margin-top & margin-bottom */
|
|
38
|
+
my?: number | string
|
|
39
|
+
/** shorthand for css:margin-left & margin-right */
|
|
40
|
+
mx?: number | string
|
|
41
|
+
/** shorthand for css:max-width */
|
|
42
|
+
maxW?: number | string
|
|
43
|
+
/** shorthand for css:min-width */
|
|
44
|
+
minW?: number | string
|
|
45
|
+
/** shorthand for css:padding */
|
|
46
|
+
p?: number | string
|
|
47
|
+
/** shorthand for css:padding-left */
|
|
48
|
+
pl?: number | string
|
|
49
|
+
/** shorthand for css:padding-right */
|
|
50
|
+
pr?: number | string
|
|
51
|
+
/** shorthand for css:padding-top */
|
|
52
|
+
pt?: number | string
|
|
53
|
+
/** shorthand for css:padding-bottom */
|
|
54
|
+
pb?: number | string
|
|
55
|
+
/** shorthand for css:padding-top & padding-bottom */
|
|
56
|
+
py?: number | string
|
|
57
|
+
/** shorthand for css:padding-left & padding-right */
|
|
58
|
+
px?: number | string
|
|
59
|
+
/** shorthand for css:position */
|
|
60
|
+
pos?: number | string
|
|
61
|
+
/** shorthand for css:text-align */
|
|
62
|
+
ta?: string
|
|
63
|
+
/** shorthand for css:width */
|
|
64
|
+
w?: number | string
|
|
65
|
+
/** shorthand for css:z-index */
|
|
66
|
+
z?: number | string
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Expand short-hand css props to full
|
|
71
71
|
*/
|
|
72
72
|
export function expandShorthands(css: string) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
css = `\n${css}` // inject a newline to make the regex easier
|
|
74
|
+
// Handle 'mx', 'my', 'px', 'py'
|
|
75
|
+
css = css
|
|
76
|
+
.replace(/([mp])x:([^;]*)/g, "$1l:$2;\n$1r:$2")
|
|
77
|
+
.replace(/([mp])y:([^;]*);/g, "$1t:$2;\n$1b:$2")
|
|
78
|
+
Object.entries(shorthandPropsMap).forEach(([k, v]) => {
|
|
79
|
+
css = css.replace(new RegExp(`([ \n\t;])${k}:`, "g"), `$1${v}:`)
|
|
80
|
+
})
|
|
81
|
+
return css.trim()
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Map shorthand props to their full css prop
|
|
86
86
|
*/
|
|
87
87
|
export const shorthandPropsMap: Record<
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
keyof Omit<ShorthandProps, "mx" | "my" | "px" | "py">,
|
|
89
|
+
string
|
|
90
90
|
> = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
91
|
+
ai: "align-items",
|
|
92
|
+
b: "border",
|
|
93
|
+
br: "border-radius",
|
|
94
|
+
bg: "background",
|
|
95
|
+
c: "color",
|
|
96
|
+
d: "display",
|
|
97
|
+
f: "flex",
|
|
98
|
+
fd: "flex-direction",
|
|
99
|
+
i: "inset",
|
|
100
|
+
h: "height",
|
|
101
|
+
jc: "justify-content",
|
|
102
|
+
m: "margin",
|
|
103
|
+
ml: "margin-left",
|
|
104
|
+
mr: "margin-right",
|
|
105
|
+
mt: "margin-top",
|
|
106
|
+
mb: "margin-bottom",
|
|
107
|
+
maxW: "max-width",
|
|
108
|
+
minW: "min-width",
|
|
109
|
+
p: "padding",
|
|
110
|
+
pl: "padding-left",
|
|
111
|
+
pr: "padding-right",
|
|
112
|
+
pt: "padding-top",
|
|
113
|
+
pb: "padding-bottom",
|
|
114
|
+
pos: "position",
|
|
115
|
+
ta: "text-align",
|
|
116
|
+
w: "width",
|
|
117
|
+
z: "z-index",
|
|
118
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slimr/css",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.76",
|
|
4
4
|
"author": "Brian Dombrowski",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"private": false,
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"start": "nodemon -w src -e '*' -x 'npm run build && cd ../demo && npm start'"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@slimr/util": "^3.2.
|
|
37
|
+
"@slimr/util": "^3.2.69"
|
|
38
38
|
}
|
|
39
39
|
}
|