@magic/css 0.7.43 → 0.7.47
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/README.md +14 -1
- package/package.json +8 -8
- package/src/parse/index.mjs +19 -15
- package/src/stringify/index.mjs +1 -1
- package/src/stringify/props.mjs +11 -1
- package/src/stringify/recurseStringify.mjs +6 -3
package/README.md
CHANGED
|
@@ -539,6 +539,19 @@ update dependencies
|
|
|
539
539
|
* use single quotes in output css
|
|
540
540
|
* add cli
|
|
541
541
|
|
|
542
|
-
#### 0.7.44
|
|
542
|
+
#### 0.7.44
|
|
543
|
+
* css props can be arrays to provide css overloads `{ color: ['green', 'red'] }` turns into `color: green; color: red;`
|
|
544
|
+
* update dependencies
|
|
545
|
+
|
|
546
|
+
#### 0.7.45
|
|
547
|
+
update dependencies
|
|
548
|
+
|
|
549
|
+
#### 0.7.46
|
|
550
|
+
update dependencies
|
|
551
|
+
|
|
552
|
+
#### 0.7.47
|
|
553
|
+
update dependencies
|
|
554
|
+
|
|
555
|
+
#### 0.7.48 - unreleased
|
|
543
556
|
...
|
|
544
557
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magic/css",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.47",
|
|
4
4
|
"author": "Wizards & Witches",
|
|
5
5
|
"description": "css in js",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
},
|
|
38
38
|
"main": "src/index.mjs",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@magic/cases": "0.0.
|
|
41
|
-
"@magic/deep": "0.1.
|
|
42
|
-
"@magic/fs": "0.0.
|
|
43
|
-
"@magic/log": "0.1.
|
|
44
|
-
"@magic/types": "0.1.
|
|
40
|
+
"@magic/cases": "0.0.6",
|
|
41
|
+
"@magic/deep": "0.1.10",
|
|
42
|
+
"@magic/fs": "0.0.21",
|
|
43
|
+
"@magic/log": "0.1.12",
|
|
44
|
+
"@magic/types": "0.1.18",
|
|
45
45
|
"autoprefixer": "10.4.0",
|
|
46
46
|
"postcss": "8.4.5"
|
|
47
47
|
},
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"@magic-modules/pre": "0.0.11",
|
|
53
53
|
"@magic-themes/docs": "0.0.14",
|
|
54
54
|
"@magic/core": "0.0.133",
|
|
55
|
-
"@magic/format": "0.0.
|
|
56
|
-
"@magic/test": "0.
|
|
55
|
+
"@magic/format": "0.0.35",
|
|
56
|
+
"@magic/test": "0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"css-in-js",
|
package/src/parse/index.mjs
CHANGED
|
@@ -29,14 +29,12 @@ const recurseParse = (mod, opts) => {
|
|
|
29
29
|
let children = []
|
|
30
30
|
const props = {}
|
|
31
31
|
|
|
32
|
-
// media and keyframes are special, they provide a full body of css rules
|
|
33
32
|
if (parent.startsWith('@keyframes') || parent.startsWith('@media')) {
|
|
33
|
+
// media and keyframes are special, they provide a full body of css rules
|
|
34
34
|
const i = parse(items)
|
|
35
35
|
return [parent, i]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// handle font face declarations that are expected to expand
|
|
39
|
-
if (parent.startsWith('@font-face')) {
|
|
36
|
+
} else if (parent.startsWith('@font-face')) {
|
|
37
|
+
// handle font face declarations that are expected to expand
|
|
40
38
|
let i = items
|
|
41
39
|
if (is.string(items.url)) {
|
|
42
40
|
i = [items]
|
|
@@ -47,14 +45,18 @@ const recurseParse = (mod, opts) => {
|
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
if (is.objectNative(items)) {
|
|
49
|
+
Object.entries(items).forEach(([name, item]) => {
|
|
50
|
+
if (is.array(item)) {
|
|
51
|
+
props[name] = item
|
|
52
|
+
} else if (is.objectNative(item)) {
|
|
53
|
+
name = getSelector(parent, name)
|
|
54
|
+
children = deep.merge(children, recurseParse([name, item], opts))
|
|
55
|
+
} else {
|
|
56
|
+
props[name] = item
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
if (is.empty(props)) {
|
|
60
62
|
if (!is.empty(children)) {
|
|
@@ -102,12 +104,14 @@ const parse = (styles, opts = {}) => {
|
|
|
102
104
|
styles = styles(opts)
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
// this might trigger additionally to the is.function if statement above
|
|
106
107
|
if (is.array(styles)) {
|
|
108
|
+
// if styles are an array, map over the items
|
|
107
109
|
styles = styles.map(s => recurseParse(s, opts))
|
|
108
|
-
} else if (
|
|
110
|
+
} else if (is.objectNative(styles)) {
|
|
111
|
+
// styles are an object
|
|
109
112
|
styles = Object.entries(styles).map(s => recurseParse(s, opts))
|
|
110
113
|
} else {
|
|
114
|
+
// unknown styles
|
|
111
115
|
log.error('invalid styles received', styles)
|
|
112
116
|
}
|
|
113
117
|
|
package/src/stringify/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const stringify = async (styles, opts = {}) => {
|
|
|
25
25
|
|
|
26
26
|
const parsed = parse(styles, opts)
|
|
27
27
|
|
|
28
|
-
const stringified = recurseStringify(parsed, plugins.stringify)
|
|
28
|
+
const stringified = recurseStringify(parsed, plugins.stringify, opts)
|
|
29
29
|
|
|
30
30
|
/*
|
|
31
31
|
* test the resulting css using postcss and autoprefix vendors where needed.
|
package/src/stringify/props.mjs
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import cases from '@magic/cases'
|
|
2
|
+
import is from '@magic/types'
|
|
2
3
|
|
|
3
4
|
export const stringifyProps = props =>
|
|
4
5
|
Object.entries(props)
|
|
5
|
-
.map(([k, v]) =>
|
|
6
|
+
.map(([k, v]) => {
|
|
7
|
+
const kebab = cases.kebab(k)
|
|
8
|
+
|
|
9
|
+
// handle css overloads (color: ['green', 'red'] turns into "color: green; color: red;")
|
|
10
|
+
if (is.array(v)) {
|
|
11
|
+
return v.map(o => `${kebab}: ${o};`).join(' ')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return `${kebab}: ${v};`
|
|
15
|
+
})
|
|
6
16
|
.join(' ')
|
|
7
17
|
|
|
8
18
|
export default stringifyProps
|
|
@@ -2,9 +2,10 @@ import is from '@magic/types'
|
|
|
2
2
|
|
|
3
3
|
import stringifyProps from './props.mjs'
|
|
4
4
|
|
|
5
|
-
export const recurseStringify = (res, plugins = []) => {
|
|
5
|
+
export const recurseStringify = (res, plugins = [], opts = {}) => {
|
|
6
6
|
if (is.array(res)) {
|
|
7
7
|
const [name, items] = res
|
|
8
|
+
|
|
8
9
|
if (is.string(name)) {
|
|
9
10
|
let result = ''
|
|
10
11
|
Object.entries(plugins).forEach(([lookup, fn]) => {
|
|
@@ -12,14 +13,16 @@ export const recurseStringify = (res, plugins = []) => {
|
|
|
12
13
|
result = fn({ name, items, plugins })
|
|
13
14
|
}
|
|
14
15
|
})
|
|
16
|
+
|
|
15
17
|
if (result) {
|
|
16
18
|
return result
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
return res.map(r => recurseStringify(r, plugins)).join(' ')
|
|
22
|
+
return res.map(r => recurseStringify(r, plugins, opts)).join(' ')
|
|
21
23
|
} else if (is.object(res)) {
|
|
22
|
-
|
|
24
|
+
const stringified = stringifyProps(res)
|
|
25
|
+
return `{ ${stringified} }\n`
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
return res
|