@maizzle/framework 4.4.3 → 4.4.4

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.3",
3
+ "version": "4.4.4",
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",
@@ -6,16 +6,19 @@ const matchHelper = require('posthtml-match-helper')
6
6
  const defaultConfig = require('../generators/posthtml/defaultConfig')
7
7
 
8
8
  module.exports = async (html, config = {}) => {
9
- if (get(config, 'removeInlinedClasses') === false) {
9
+ if (get(config, 'removeInlinedSelectors') === false) {
10
10
  return html
11
11
  }
12
12
 
13
- const posthtmlOptions = merge(defaultConfig, get(config, 'build.posthtml.options', {}))
13
+ const options = {
14
+ posthtml: merge(defaultConfig, get(config, 'build.posthtml.options', {})),
15
+ removeUnusedCSS: config
16
+ }
14
17
 
15
- return posthtml([plugin(posthtmlOptions)]).process(html, posthtmlOptions).then(result => result.html)
18
+ return posthtml([plugin(options)]).process(html, options.posthtml).then(result => result.html)
16
19
  }
17
20
 
18
- const plugin = posthtmlOptions => tree => {
21
+ const plugin = (options = {}) => tree => {
19
22
  const process = node => {
20
23
  // For each style tag...
21
24
  if (node.tag === 'style') {
@@ -41,8 +44,16 @@ const plugin = posthtmlOptions => tree => {
41
44
  }
42
45
 
43
46
  try {
47
+ const safelist = get(options.removeUnusedCSS, 'whitelist', [])
48
+
44
49
  // If we find the selector in the HTML...
45
50
  tree.match(matchHelper(selector), n => {
51
+ // If the selector is safelisted, preserve it
52
+ if (safelist.some(item => item.endsWith(selector) || item.startsWith(selector))) {
53
+ preservedClasses.push(selector)
54
+ return n
55
+ }
56
+
46
57
  const parsedAttrs = parseAttrs(n.attrs)
47
58
  const classAttr = get(parsedAttrs, 'class', [])
48
59
  const styleAttr = get(parsedAttrs, 'style', {})
@@ -64,7 +75,7 @@ const plugin = posthtmlOptions => tree => {
64
75
 
65
76
  // Fix issue with .compose() automatically quoting attributes with no values
66
77
  Object.entries(n.attrs).forEach(([name, value]) => {
67
- if (value === '' && get(posthtmlOptions, 'recognizeNoValueAttribute') === true) {
78
+ if (value === '' && get(options.posthtml, 'recognizeNoValueAttribute') === true) {
68
79
  n.attrs[name] = true
69
80
  }
70
81
  })
@@ -36,7 +36,7 @@ module.exports = async (html, config = {}, direct = false) => {
36
36
  whitelist: [...get(config, 'whitelist', []), ...safelist]
37
37
  }
38
38
 
39
- const options = merge(defaultOptions, get(config, 'removeUnusedCSS', {}))
39
+ const options = merge(defaultOptions, config)
40
40
 
41
41
  /**
42
42
  * Remove possibly inlined selectors, as long as we're not calling