@maizzle/framework 4.4.0-beta.1 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "4.4.0-beta.1",
3
+ "version": "4.4.0-beta.3",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "main": "src/index.js",
@@ -61,13 +61,11 @@
61
61
  "posthtml-base-url": "^1.0.1",
62
62
  "posthtml-component": "^1.0.0-beta.16",
63
63
  "posthtml-content": "^0.1.0",
64
- "posthtml-expressions": "^1.8.1",
65
64
  "posthtml-extend": "^0.6.0",
66
65
  "posthtml-extra-attributes": "^1.0.0",
67
66
  "posthtml-fetch": "^2.2.0",
68
67
  "posthtml-markdownit": "^1.3.0",
69
68
  "posthtml-match-helper": "^1.0.3",
70
- "posthtml-modules": "^0.9.0",
71
69
  "posthtml-mso": "^1.0.4",
72
70
  "posthtml-postcss-merge-longhand": "^1.0.2",
73
71
  "posthtml-safe-class-names": "^2.0.0",
@@ -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, true)
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
- root.walkRules(rule => {
25
- // Skip media queries and such...
26
- if (rule.parent.type === 'atrule') {
27
- return
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 attribute
43
- remove(classAttr, s => selector.includes(s))
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.remove()
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 = {}, direct = false) => {
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 = typeof config === 'boolean' && config ?
40
- defaultOptions :
41
- merge(defaultOptions, get(config, 'removeUnusedCSS', config))
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
  }