@maizzle/framework 5.0.2 → 5.0.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": "5.0.2",
3
+ "version": "5.0.3",
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",
@@ -9,7 +9,6 @@ import isEmpty from 'lodash-es/isEmpty.js'
9
9
  import safeParser from 'postcss-safe-parser'
10
10
  import isObject from 'lodash-es/isObject.js'
11
11
  import { parser as parse } from 'posthtml-parser'
12
- import { parseCSSRule } from '../utils/string.js'
13
12
  import { useAttributeSizes } from './useAttributeSizes.js'
14
13
  import { getPosthtmlOptions } from '../posthtml/defaultConfig.js'
15
14
 
@@ -166,6 +165,13 @@ export async function inline(html = '', options = {}) {
166
165
  }
167
166
  })
168
167
 
168
+ /**
169
+ * CSS optimizations
170
+ *
171
+ * 1. `preferUnitlessValues` - Replace unit values with `0` where possible
172
+ * 2. `removeInlinedSelectors` - Remove inlined selectors from the HTML
173
+ */
174
+
169
175
  // Loop over selectors that we found in the <style> tags
170
176
  selectors.forEach(({ name, prop }) => {
171
177
  const elements = $(name).get()
@@ -176,11 +182,16 @@ export async function inline(html = '', options = {}) {
176
182
  elements.forEach((el) => {
177
183
  // Get a `property|value` list from the inline style attribute
178
184
  const styleAttr = $(el).attr('style')
179
- let inlineStyles = {}
185
+ const inlineStyles = {}
180
186
 
187
+ // 1. `preferUnitlessValues`
181
188
  if (styleAttr) {
182
- inlineStyles = styleAttr.split(';').reduce((acc, i) => {
183
- let { property, value } = parseCSSRule(i)
189
+ // Parse the inline styles using postcss
190
+ const root = postcss.parse(`* { ${styleAttr} }`)
191
+
192
+ root.first.each((decl) => {
193
+ const property = decl.prop
194
+ let value = decl.value
184
195
 
185
196
  if (value && options.preferUnitlessValues) {
186
197
  value = value.replace(
@@ -190,11 +201,9 @@ export async function inline(html = '', options = {}) {
190
201
  }
191
202
 
192
203
  if (property) {
193
- acc[property] = value
204
+ inlineStyles[property] = value
194
205
  }
195
-
196
- return acc
197
- }, {})
206
+ })
198
207
 
199
208
  // Update the element's style attribute with the new value
200
209
  $(el).attr(
@@ -206,6 +215,7 @@ export async function inline(html = '', options = {}) {
206
215
  // Get the classes from the element's class attribute
207
216
  const classes = $(el).attr('class')
208
217
 
218
+ // 2. `removeInlinedSelectors`
209
219
  if (options.removeInlinedSelectors && classes) {
210
220
  const classList = classes.split(' ')
211
221
 
@@ -174,27 +174,6 @@ export function getFileExtensionsFromPattern(pattern) {
174
174
  return ['html'] // No recognizable extension pattern, default to 'html'
175
175
  }
176
176
 
177
- export function parseCSSRule(rule) {
178
- // Step 1: Trim the input string
179
- rule = rule.trim()
180
-
181
- // Step 2: Find the index of the first colon
182
- const colonIndex = rule.indexOf(':')
183
-
184
- // Step 3: Extract property and value parts
185
- if (colonIndex === -1) {
186
- return {
187
- property: '',
188
- value: ''
189
- }
190
- }
191
-
192
- const property = rule.slice(0, colonIndex).trim()
193
- const value = rule.slice(colonIndex + 1).trim()
194
-
195
- return { property, value }
196
- }
197
-
198
177
  /**
199
178
  * Normalize a string by removing extra whitespace.
200
179
  *