@maizzle/framework 5.0.0-beta.33 → 5.0.0-beta.34

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": "5.0.0-beta.33",
3
+ "version": "5.0.0-beta.34",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,7 +48,6 @@
48
48
  "html-emails"
49
49
  ],
50
50
  "dependencies": {
51
- "@csstools/css-calc": "^2.0.1",
52
51
  "@maizzle/cli": "next",
53
52
  "cheerio": "^1.0.0",
54
53
  "chokidar": "^3.6.0",
@@ -68,6 +67,7 @@
68
67
  "ora": "^8.1.0",
69
68
  "pathe": "^1.1.2",
70
69
  "postcss": "^8.4.49",
70
+ "postcss-calc": "^10.0.2",
71
71
  "postcss-css-variables": "^0.19.0",
72
72
  "postcss-import": "^16.1.0",
73
73
  "postcss-safe-parser": "^7.0.0",
@@ -13,6 +13,7 @@ import { getPosthtmlOptions } from './defaultConfig.js'
13
13
 
14
14
  // PostCSS
15
15
  import tailwindcss from 'tailwindcss'
16
+ import postcssCalc from 'postcss-calc'
16
17
  import postcssImport from 'postcss-import'
17
18
  import cssVariables from 'postcss-css-variables'
18
19
  import postcssSafeParser from 'postcss-safe-parser'
@@ -20,13 +21,21 @@ import postcssSafeParser from 'postcss-safe-parser'
20
21
  import defaultComponentsConfig from './defaultComponentsConfig.js'
21
22
 
22
23
  export async function process(html = '', config = {}) {
24
+ /**
25
+ * Configure PostCSS pipeline. Plugins defined and added here
26
+ * will apply to all `<style>` tags in the HTML.
27
+ */
23
28
  const resolveCSSProps = get(config, 'css.resolveProps')
29
+ const resolveCalc = get(config, 'css.resolveCalc') !== false
30
+ ? get(config, 'css.resolveCalc', { precision: 2 }) // it's true by default, use default precision 2
31
+ : false
24
32
 
25
33
  const postcssPlugin = posthtmlPostcss(
26
34
  [
27
35
  postcssImport(),
28
36
  tailwindcss(get(config, 'css.tailwind', {})),
29
37
  resolveCSSProps !== false && cssVariables(resolveCSSProps),
38
+ resolveCalc !== false && postcssCalc(resolveCalc),
30
39
  ...get(config, 'postcss.plugins', []),
31
40
  ],
32
41
  merge(
@@ -38,6 +47,10 @@ export async function process(html = '', config = {}) {
38
47
  )
39
48
  )
40
49
 
50
+ /**
51
+ * Define PostHTML options by merging user-provided ones
52
+ * on top of a default configuration.
53
+ */
41
54
  const posthtmlOptions = getPosthtmlOptions(get(config, 'posthtml.options', {}))
42
55
 
43
56
  const componentsUserOptions = get(config, 'components', {})
@@ -2,11 +2,9 @@ import juice from 'juice'
2
2
  import postcss from 'postcss'
3
3
  import get from 'lodash-es/get.js'
4
4
  import has from 'lodash-es/has.js'
5
- import { defu as merge } from 'defu'
6
5
  import * as cheerio from 'cheerio/slim'
7
6
  import remove from 'lodash-es/remove.js'
8
7
  import { render } from 'posthtml-render'
9
- import { calc } from '@csstools/css-calc'
10
8
  import isEmpty from 'lodash-es/isEmpty.js'
11
9
  import safeParser from 'postcss-safe-parser'
12
10
  import isObject from 'lodash-es/isObject.js'
@@ -30,9 +28,7 @@ export async function inline(html = '', options = {}) {
30
28
  const removeStyleTags = get(options, 'removeStyleTags', false)
31
29
  const css = get(options, 'customCSS', false)
32
30
 
33
- options.resolveCSSVariables = get(options, 'resolveCSSVariables', true)
34
31
  options.removeInlinedSelectors = get(options, 'removeInlinedSelectors', true)
35
- options.resolveCalc = get(options, 'resolveCalc', true)
36
32
  options.preferUnitlessValues = get(options, 'preferUnitlessValues', true)
37
33
  options.safelist = new Set([
38
34
  ...get(options, 'safelist', []),
@@ -147,37 +143,6 @@ export async function inline(html = '', options = {}) {
147
143
 
148
144
  // For each rule in the CSS block we're parsing
149
145
  root.walkRules(rule => {
150
- // Keep track of declarations in the rule
151
- const declarations = new Set()
152
-
153
- rule.walkDecls(decl => {
154
- // Resolve calc() values to static values
155
- if (options.resolveCalc) {
156
- decl.value = decl.value.includes('calc(') ? calc(decl.value, { precision: 2 }) : decl.value
157
- }
158
-
159
- declarations.add(decl)
160
- })
161
-
162
- /**
163
- * Remove duplicate declarations
164
- *
165
- * Only do so if the `resolveCSSVariables` option is enabled,
166
- * otherwise we'll end up removing all declarations that use CSS variables
167
- */
168
- if (options.resolveCSSVariables) {
169
- Array.from(declarations)
170
- /**
171
- * Consider only declarations with a value that includes any of the other declarations' property
172
- * So a decl like color(var(--text-color)) will be removed if there's a decl with a property of --text-color
173
- * */
174
- .filter(decl =>
175
- Array.from(declarations).some(otherDecl => decl.value.includes(otherDecl.prop))
176
- || decl.prop.startsWith('--')
177
- )
178
- .map(decl => decl.remove())
179
- }
180
-
181
146
  const { selector } = rule
182
147
 
183
148
  selectors.add({
@@ -186,7 +151,6 @@ export async function inline(html = '', options = {}) {
186
151
  })
187
152
 
188
153
  // Preserve pseudo selectors
189
- // TODO: revisit pseudos list
190
154
  if ([':hover', ':active', ':focus', ':visited', ':link', ':before', ':after'].some(i => selector.includes(i))) {
191
155
  options.safelist.add(selector)
192
156
  }
@@ -218,10 +182,6 @@ export async function inline(html = '', options = {}) {
218
182
  inlineStyles = styleAttr.split(';').reduce((acc, i) => {
219
183
  let { property, value } = parseCSSRule(i)
220
184
 
221
- if (value && options.resolveCalc) {
222
- value = value.includes('calc') ? calc(value, { precision: 2 }) : value
223
- }
224
-
225
185
  if (value && options.preferUnitlessValues) {
226
186
  value = value.replace(
227
187
  /\b0(px|rem|em|%|vh|vw|vmin|vmax|in|cm|mm|pt|pc|ex|ch)\b/g,