@maizzle/framework 4.4.0-beta.2 → 4.4.0-beta.3
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/package.json
CHANGED
|
@@ -28,7 +28,6 @@ exports.process = async (html, config) => {
|
|
|
28
28
|
html = await inline(html, config)
|
|
29
29
|
html = await shorthandInlineCSS(html, config)
|
|
30
30
|
html = await removeUnusedCSS(html, config)
|
|
31
|
-
html = await removeInlinedClasses(html, config)
|
|
32
31
|
html = await removeInlineSizes(html, config)
|
|
33
32
|
html = await removeInlineBgColor(html, config)
|
|
34
33
|
html = await removeAttributes(html, config)
|
|
@@ -54,7 +53,7 @@ exports.addURLParams = (html, config) => addURLParams(html, config, true)
|
|
|
54
53
|
exports.preventWidows = (html, config) => preventWidows(html, config)
|
|
55
54
|
exports.replaceStrings = (html, config) => replaceStrings(html, config, true)
|
|
56
55
|
exports.safeClassNames = (html, config) => safeClassNames(html, config, true)
|
|
57
|
-
exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config
|
|
56
|
+
exports.removeUnusedCSS = (html, config) => removeUnusedCSS(html, config)
|
|
58
57
|
exports.removeAttributes = (html, config) => removeAttributes(html, config, true)
|
|
59
58
|
exports.attributeToStyle = (html, config) => attributeToStyle(html, config, true)
|
|
60
59
|
exports.removeInlineSizes = (html, config) => removeInlineSizes(html, config, true)
|
|
@@ -20,16 +20,26 @@ const plugin = posthtmlOptions => tree => {
|
|
|
20
20
|
// For each style tag...
|
|
21
21
|
if (node.tag === 'style') {
|
|
22
22
|
const {root} = postcss().process(node.content)
|
|
23
|
+
const preservedClasses = []
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
25
|
+
// Preserve selectors in at rules
|
|
26
|
+
root.walkAtRules(rule => {
|
|
27
|
+
if (['media', 'supports'].includes(rule.name)) {
|
|
28
|
+
rule.walkRules(rule => {
|
|
29
|
+
preservedClasses.push(rule.selector)
|
|
30
|
+
})
|
|
28
31
|
}
|
|
32
|
+
})
|
|
29
33
|
|
|
34
|
+
root.walkRules(rule => {
|
|
30
35
|
const {selector} = rule
|
|
31
36
|
const prop = get(rule.nodes[0], 'prop')
|
|
32
37
|
|
|
38
|
+
// Preserve pseudo selectors
|
|
39
|
+
if (selector.includes(':')) {
|
|
40
|
+
preservedClasses.push(selector)
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
try {
|
|
34
44
|
// If we find the selector in the HTML...
|
|
35
45
|
tree.match(matchHelper(selector), n => {
|
|
@@ -39,23 +49,16 @@ const plugin = posthtmlOptions => tree => {
|
|
|
39
49
|
|
|
40
50
|
// If the class is in the style attribute (inlined), remove it
|
|
41
51
|
if (has(styleAttr, prop)) {
|
|
42
|
-
// Remove the class
|
|
43
|
-
|
|
52
|
+
// Remove the class as long as it's not a preserved class
|
|
53
|
+
if (!preservedClasses.some(item => item.endsWith(selector) || item.startsWith(selector))) {
|
|
54
|
+
remove(classAttr, classToRemove => selector.includes(classToRemove))
|
|
55
|
+
}
|
|
44
56
|
|
|
45
57
|
// Remove the rule in the <style> tag
|
|
46
|
-
rule.
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Remove from <style> selectors that were used to create shorthand declarations
|
|
51
|
-
* like `margin: 0 0 0 16px` (transformed with mergeLonghand when inlining).
|
|
52
|
-
*/
|
|
53
|
-
Object.keys(styleAttr).forEach(key => {
|
|
54
|
-
if (prop && prop.includes(key)) {
|
|
58
|
+
if (rule.parent.type !== 'atrule') {
|
|
55
59
|
rule.remove()
|
|
56
|
-
remove(classAttr, s => selector.includes(s))
|
|
57
60
|
}
|
|
58
|
-
}
|
|
61
|
+
}
|
|
59
62
|
|
|
60
63
|
n.attrs = parsedAttrs.compose()
|
|
61
64
|
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
const {comb} = require('email-comb')
|
|
2
2
|
const {get, merge} = require('lodash')
|
|
3
|
+
const removeInlinedClasses = require('./removeInlinedSelectors')
|
|
3
4
|
|
|
4
|
-
module.exports = async (html, config = {}
|
|
5
|
+
module.exports = async (html, config = {}) => {
|
|
6
|
+
// If it's explicitly disabled, return the HTML
|
|
5
7
|
if (get(config, 'removeUnusedCSS') === false) {
|
|
6
8
|
return html
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
if (!direct && !get(config, 'removeUnusedCSS')) {
|
|
10
|
-
return html
|
|
11
|
-
}
|
|
12
|
-
|
|
13
11
|
const safelist = [
|
|
14
12
|
'*body*', // Gmail
|
|
15
13
|
'.gmail*', // Gmail
|
|
@@ -36,9 +34,9 @@ module.exports = async (html, config = {}, direct = false) => {
|
|
|
36
34
|
whitelist: [...get(config, 'whitelist', []), ...safelist]
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
const options =
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const options = merge(defaultOptions, get(config, 'removeUnusedCSS', config))
|
|
38
|
+
|
|
39
|
+
html = await removeInlinedClasses(html, options)
|
|
42
40
|
|
|
43
41
|
return comb(html, options).result
|
|
44
42
|
}
|